Overview
ThePhoneNumberToTimeZonesMapper class identifies the timezone(s) where a phone number is located. It returns an array of timezone strings in IANA timezone format (e.g., “America/New_York”, “Europe/Zurich”).
Geographic numbers typically return specific timezones, while non-geographic numbers (like toll-free) may return multiple timezones covering the entire country.
Getting an Instance
The timezone mapper uses a singleton pattern. Get an instance using the staticgetInstance() method:
Optional class name for custom timezone mapping data. Only needed for advanced use cases with custom data sources.
Methods
getTimeZonesForNumber()
Returns an array of timezone strings for the given phone number. For geographical numbers, this typically returns one or a few specific timezones. For non-geographical numbers (toll-free, shared-cost, etc.), it may return all timezones in the country.The phone number to get timezone information for.
An array of timezone strings in IANA format. Returns
["Etc/Unknown"] if:- The number is invalid
- No timezone data is available
- The number type is unknown
Geographic Number Example
Geographic (fixed-line) numbers typically return specific timezones:Non-Geographic Number Example
Non-geographic numbers like toll-free can be from anywhere in the country, so they return all possible timezones:Swiss Number Example
getTimeZonesForGeographicalNumber()
Returns timezones for a geographical phone number. Assumes the number has already been validated as geographical.A valid geographical phone number.
An array of timezone strings, or
["Etc/Unknown"] if no mapping is found.This method assumes the number is geographical (fixed-line or mobile). For most use cases, prefer
getTimeZonesForNumber() which automatically determines the number type.getUnknownTimeZone()
Returns the constant string used to represent unknown timezones.The string “Etc/Unknown”
Example
Complete Example
Understanding Results
Single Timezone Result
Most geographic phone numbers return a single timezone:Multiple Timezone Results
Some scenarios return multiple timezones:-
Non-geographic numbers (toll-free, shared cost, etc.)
- Can be from anywhere in the country
- Returns all timezones for that country/region
-
Numbers spanning multiple zones
- Some area codes cover multiple timezones
- Returns all applicable zones
-
Country-level results
- When specific geographic data isn’t available
- Returns all timezones for the country
Timezone Format
All timezone strings use the IANA timezone database format:- North America:
America/New_York,America/Chicago,America/Los_Angeles - Europe:
Europe/London,Europe/Paris,Europe/Zurich - Asia:
Asia/Tokyo,Asia/Hong_Kong,Asia/Dubai - Pacific:
Pacific/Auckland,Pacific/Honolulu - Unknown:
Etc/Unknown
DateTimeZone class:
Use Cases
Common applications:
- Scheduling calls - Determine appropriate calling times
- Time-based features - Show local time for phone number owners
- Business hours - Calculate operating hours for different regions
- Analytics - Timezone-based reporting and analysis
- Compliance - Respect calling time restrictions by timezone
Data Availability
Timezone mapping works best for:- Fixed-line numbers - Usually tied to specific geographic areas
- Mobile numbers - When registered to specific regions
- Countries with good data coverage - Major markets have detailed mapping
- Non-geographic numbers return country-level timezones (many results)
- Some regions may have incomplete data
- Mobile numbers may not reflect current user location
- Returns
"Etc/Unknown"when no data is available