timepicker-ui
4.7.0GitHub
timepicker-ui
Plugins / Timezone Selector

Timezone Plugin

Add a timezone selector dropdown to the timepicker. Display-only feature - does not convert times automatically.

The selector is a select-only combobox. Focus it with Tab, open it with Enter, Space or the arrow keys, and type letters to jump to the next timezone that starts with them.

Basic Timezone Selector

#
import { TimepickerUI, PluginRegistry } from 'timepicker-ui';
import { TimezonePlugin } from 'timepicker-ui/plugins/timezone';
PluginRegistry.register(TimezonePlugin);
const picker = new TimepickerUI(input, {
timezone: {
enabled: true
}
});
picker.create();

With Default Timezone

#
import { TimepickerUI, PluginRegistry } from 'timepicker-ui';
import { TimezonePlugin } from 'timepicker-ui/plugins/timezone';
PluginRegistry.register(TimezonePlugin);
const picker = new TimepickerUI(input, {
timezone: {
enabled: true,
default: 'Europe/London'
}
});
picker.create();

Custom Timezone List

#
import { TimepickerUI, PluginRegistry } from 'timepicker-ui';
import { TimezonePlugin } from 'timepicker-ui/plugins/timezone';
PluginRegistry.register(TimezonePlugin);
const picker = new TimepickerUI(input, {
timezone: {
enabled: true,
default: 'America/New_York',
list: [
'America/New_York',
'America/Los_Angeles',
'Europe/London',
'Europe/Paris',
'Asia/Tokyo'
]
}
});
picker.create();

Custom Label

#
import { TimepickerUI, PluginRegistry } from 'timepicker-ui';
import { TimezonePlugin } from 'timepicker-ui/plugins/timezone';
PluginRegistry.register(TimezonePlugin);
const picker = new TimepickerUI(input, {
timezone: {
enabled: true
},
labels: {
timezone: 'Time Zone'
}
});
picker.create();

Extend the Built-in List

#

The plugin entry exports DEFAULT_TIMEZONES, the list the selector shows by default, and getTimezoneList(), which returns { id, label, offset } for each ID the browser knows. Spread the default list to add a zone. New in 4.7.0.

index.ts
import { TimepickerUI, PluginRegistry } from 'timepicker-ui';
import {
TimezonePlugin,
getTimezoneList,
DEFAULT_TIMEZONES
} from 'timepicker-ui/plugins/timezone';
PluginRegistry.register(TimezonePlugin);
const list = [...DEFAULT_TIMEZONES, 'Europe/Warsaw'];
const zones = getTimezoneList(list);
const picker = new TimepickerUI(input, {
timezone: {
enabled: true,
default: 'Europe/Warsaw',
list
}
});
picker.create();

Default Not in the List

#

A timezone.default that is not in the list falls back to the browser timezone, or the first entry, and emits an error event once. New in 4.7.0.

index.ts
const picker = new TimepickerUI(input, {
timezone: { enabled: true, default: 'Europe/Warsaw' }
});
picker.create();
picker.on('error', (data) => {
console.warn(data.error);
// timezone.default "Europe/Warsaw" is not in the timezone list, using "Europe/Paris"
});
Esc