Check Timezone Identifiers
Check whether provided value is a timezone identifier or not using native JS API or comprehensive TZ database.
isValidTimeZoneId()
Validates whether the provided value is a recognized IANA timezone identifier from the TZ database.
See
isNativeTimeZoneIdfor lightweight native JS solution.
Signature
isValidTimeZoneId(value: unknown): value is $TimeZoneIdentifierParameters
value- The value to validate as a timezone identifier
Return Type
value is $TimeZoneIdentifier- Type predicate that returnstrueif the value is a valid IANA timezone identifier
Example
Remarks
- Comprehensive IANA TZ Database coverage - validates against all 597 identifiers including both modern canonical names and legacy aliases
- Includes both canonical and alias names - recognizes modern names like
Asia/Kolkataalongside legacy names likeAsia/Calcutta - Type predicate function - when returns
true, TypeScript narrows the type to$TimeZoneIdentifier - Case-sensitive - identifiers must match exactly (e.g.,
'America/New_York', not'america/new_york') - Larger bundle size - includes a comprehensive array of all IANA identifiers (597 entries,
~10.7 kilobytesafter minification)
Info
Full data is also available through this package subpath:
import { IANA_TZ_IDS, TIME_ZONE_IDS } from 'toolbox-x/constants';IANA_TZ_IDScontains array of identifiers whileTIME_ZONE_IDScontains the identifiers in record style{id: { tzName: '...', offset: '...' }}
{
'Asia/Dhaka': { tzName: 'Bangladesh Standard Time', offset: 'UTC+06:00' },
// ...
}When to Use
- Future-proof applications that want to use modern canonical names
- Data validation where you need to accept both canonical and alias timezone identifiers
- Applications requiring maximum timezone coverage including modern naming conventions
- Backend systems where bundle size is less critical
Typical Use Cases
// Validate user input preferring modern names
const userInput = 'Asia/Kolkata'; // Modern systems should use this
if (isValidTimeZoneId(userInput)) {
const ch = new Chronos().timeZone(userInput); // Type-safe usage
}
// Filter valid timezone identifiers including modern names
const potentialZones = ['Asia/Dhaka', 'EST', 'Asia/Kolkata', 'UTC+06:00'];
const validZones = potentialZones.filter(isValidTimeZoneId);
// → ['Asia/Dhaka', 'EST', 'Asia/Kolkata']
// Configuration validation for modern systems
const config = { timezone: 'Asia/Kolkata' }; // Modern configuration
if (!isValidTimeZoneId(config.timezone)) {
throw new Error('Invalid timezone identifier in configuration');
}isNativeTimeZoneId()
Validates whether the provided value is a supported time zone identifier using the native JavaScript API (Intl.supportedValuesOf('timeZone')).
See
isValidTimeZoneIdfor full 597 time zone identifier support.
Signature
isNativeTimeZoneId(value: unknown): value is TimeZoneIdNativeParameters
value- The value to validate as a timezone identifier
Return Type
value is TimeZoneIdNative- Type predicate that returnstrueif the value is a valid native JS-supported time zone identifier, otherwisefalse.
Example
Remarks
- Native JavaScript validation - uses
Intl.supportedValuesOf('timeZone')for validation - Legacy-focused identifiers - many JS engines still use legacy names like
Asia/Calcuttainstead of modernAsia/Kolkata - Small bundle footprint - relies on built-in browser/Node.js APIs, no additional data (only
~700 bytesafter minification) - Type predicate function - when returns
true, TypeScript narrows the type toTimeZoneIdNative - Case-sensitive - identifiers must match exactly (e.g.,
'America/New_York', not'america/new_york') - Optimal performance - leverages native browser optimizations
- Note: Some JS engines accept modern names in
DateTimeFormatbut don't include them insupportedValuesOf()
Info
Full data is also available through this package subpath:
import { TIME_ZONES_NATIVE } from 'toolbox-x/constants';TIME_ZONES_NATIVEcontains the identifiers in record style{id: { tzName: '...', offset: '...' }}
{
'Asia/Dhaka': { tzName: 'Bangladesh Standard Time', offset: 'UTC+06:00' },
// ...
}When to Use
- Frontend applications where bundle size is critical
- Compatibility with older JS engines that use legacy timezone names
- Performance-sensitive code that benefits from native API speed
- Validation that must match exactly what the JS engine considers "supported"
Typical Use Cases
`isValidTimeZoneId` vs `isNativeTimeZoneId`
| Aspect | isValidTimeZoneId | isNativeTimeZoneId |
|---|---|---|
| Coverage | 597 identifiers (full IANA database) | 418 identifiers (engine-dependent legacy names) |
| Modern Names | ✅ Includes Asia/Kolkata (canonical) | ❌ Usually only Asia/Calcutta (legacy) |
| Bundle Size | Larger (includes array of identifiers) | Minimal (uses native APIs) |
| Performance | Good | Excellent (native optimized) |
| Use Case | Modern apps, future-proofing | JS engine compatibility, performance |
Important Note on JavaScript Engine Behavior
JavaScript engines have an interesting inconsistency:
- `Intl.supportedValuesOf('timeZone')` typically returns some legacy names like `Asia/Calcutta`
- But `new Intl.DateTimeFormat().format()` often accepts modern names like `Asia/Kolkata` and works correctly
This means `isNativeTimeZoneId` is stricter about what the engine explicitly "supports" vs what might actually work.
Decision Guide
Use isValidTimeZoneId when:
- You want to use modern canonical timezone names (
Asia/Kolkata) - Building future-proof applications
- You need consistent validation regardless of JS engine quirks
- Bundle size is not a primary concern
Use isNativeTimeZoneId when:
- Building frontend applications with bundle size constraints
- You need maximum compatibility with what JS engines explicitly support
- Performance is critical
- You're working with data that might come from
Intl.supportedValuesOf()
Practical Example
Recommendation
For most applications, use isValidTimeZoneId as it provides modern, future-proof validation. Use isNativeTimeZoneId only when you specifically need to validate against what the JS engine explicitly reports as supported.
Last updated: Fri, May 22, 2026 07:46:19AM (Coordinated Universal Time)
