react-timezone-select
Advanced tools
Comparing version 1.0.6 to 1.0.7
/// <reference types="react" /> | ||
import type { Props as ReactSelectProps } from 'react-select'; | ||
declare type ExcludeValue<T> = Pick<T, Exclude<keyof T, 'value'>>; | ||
import type { Props as ReactSelectProps } from "react-select"; | ||
import "./index.css"; | ||
declare type ExcludeValue<T> = Pick<T, Exclude<keyof T, "value">>; | ||
export declare type ICustomTimezone = { | ||
@@ -8,3 +9,3 @@ [key: string]: string; | ||
export declare const i18nTimezones: ICustomTimezone; | ||
export declare type ILabelStyle = 'original' | 'altName' | 'abbrev'; | ||
export declare type ILabelStyle = "original" | "altName" | "abbrev"; | ||
export declare enum LabelType { | ||
@@ -11,0 +12,0 @@ ORIGINAL = "original", |
@@ -1,83 +0,85 @@ | ||
import React from 'react'; | ||
import Select from 'react-select'; | ||
import spacetime from 'spacetime'; | ||
import informal from 'spacetime-informal'; | ||
import React from "react"; | ||
import Select from "react-select"; | ||
import spacetime from "spacetime"; | ||
import informal from "spacetime-informal"; | ||
import "./index.css"; | ||
export const i18nTimezones = { | ||
'Pacific/Midway': 'Midway Island, Samoa', | ||
'Pacific/Honolulu': 'Hawaii', | ||
'America/Juneau': 'Alaska', | ||
'America/Boise': 'Mountain Time', | ||
'America/Dawson': 'Dawson, Yukon', | ||
'America/Chihuahua': 'Chihuahua, La Paz, Mazatlan', | ||
'America/Phoenix': 'Arizona', | ||
'America/Chicago': 'Central Time', | ||
'America/Regina': 'Saskatchewan', | ||
'America/Mexico_City': 'Guadalajara, Mexico City, Monterrey', | ||
'America/Belize': 'Central America', | ||
'America/Detroit': 'Eastern Time', | ||
'America/Bogota': 'Bogota, Lima, Quito', | ||
'America/Caracas': 'Caracas, La Paz', | ||
'America/Santiago': 'Santiago', | ||
'America/St_Johns': 'Newfoundland and Labrador', | ||
'America/Sao_Paulo': 'Brasilia', | ||
'America/Tijuana': 'Tijuana, Pacific Time', | ||
'America/Argentina/Buenos_Aires': 'Buenos Aires, Georgetown', | ||
'America/Godthab': 'Greenland', | ||
'Atlantic/Azores': 'Azores', | ||
'Atlantic/Cape_Verde': 'Cape Verde Islands', | ||
GMT: 'UTC', | ||
'Europe/London': 'Edinburgh, London', | ||
'Europe/Dublin': 'Dublin', | ||
'Europe/Lisbon': 'Lisbon', | ||
'Africa/Casablanca': 'Casablanca, Monrovia', | ||
'Atlantic/Canary': 'Canary Islands', | ||
'Europe/Belgrade': 'Belgrade, Bratislava, Budapest, Ljubljana, Prague', | ||
'Europe/Sarajevo': 'Sarajevo, Skopje, Warsaw, Zagreb', | ||
'Europe/Brussels': 'Brussels, Copenhagen, Madrid, Paris', | ||
'Europe/Amsterdam': 'Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna', | ||
'Africa/Algiers': 'West Central Africa', | ||
'Europe/Bucharest': 'Bucharest', | ||
'Africa/Cairo': 'Cairo', | ||
'Europe/Helsinki': 'Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius', | ||
'Europe/Athens': 'Athens, Istanbul, Minsk', | ||
'Asia/Jerusalem': 'Jerusalem', | ||
'Africa/Harare': 'Harare, Pretoria', | ||
'Europe/Moscow': 'Moscow, St. Petersburg, Volgograd', | ||
'Asia/Kuwait': 'Kuwait, Riyadh', | ||
'Africa/Nairobi': 'Nairobi', | ||
'Asia/Baghdad': 'Baghdad', | ||
'Asia/Tehran': 'Tehran', | ||
'Asia/Dubai': 'Abu Dhabi, Muscat', | ||
'Asia/Baku': 'Baku, Tbilisi, Yerevan', | ||
'Asia/Kabul': 'Kabul', | ||
'Asia/Yekaterinburg': 'Ekaterinburg', | ||
'Asia/Karachi': 'Islamabad, Karachi, Tashkent', | ||
'Asia/Kolkata': 'Chennai, Kolkata, Mumbai, New Delhi', | ||
'Asia/Kathmandu': 'Kathmandu', | ||
'Asia/Dhaka': 'Astana, Dhaka', | ||
'Asia/Colombo': 'Sri Jayawardenepura', | ||
'Asia/Almaty': 'Almaty, Novosibirsk', | ||
'Asia/Rangoon': 'Yangon Rangoon', | ||
'Asia/Bangkok': 'Bangkok, Hanoi, Jakarta', | ||
'Asia/Krasnoyarsk': 'Krasnoyarsk', | ||
'Asia/Shanghai': 'Beijing, Chongqing, Hong Kong SAR, Urumqi', | ||
'Asia/Kuala_Lumpur': 'Kuala Lumpur, Singapore', | ||
'Asia/Taipei': 'Taipei', | ||
'Australia/Perth': 'Perth', | ||
'Asia/Irkutsk': 'Irkutsk, Ulaanbaatar', | ||
'Asia/Seoul': 'Seoul', | ||
'Asia/Tokyo': 'Osaka, Sapporo, Tokyo', | ||
'Asia/Yakutsk': 'Yakutsk', | ||
'Australia/Darwin': 'Darwin', | ||
'Australia/Adelaide': 'Adelaide', | ||
'Australia/Sydney': 'Canberra, Melbourne, Sydney', | ||
'Australia/Brisbane': 'Brisbane', | ||
'Australia/Hobart': 'Hobart', | ||
'Asia/Vladivostok': 'Vladivostok', | ||
'Pacific/Guam': 'Guam, Port Moresby', | ||
'Asia/Magadan': 'Magadan, Solomon Islands, New Caledonia', | ||
'Asia/Kamchatka': 'Kamchatka, Marshall Islands', | ||
'Pacific/Fiji': 'Fiji Islands', | ||
'Pacific/Auckland': 'Auckland, Wellington', | ||
'Pacific/Tongatapu': "Nuku'alofa", | ||
"Pacific/Midway": "Midway Island, Samoa", | ||
"Pacific/Honolulu": "Hawaii", | ||
"America/Juneau": "Alaska", | ||
"America/Boise": "Mountain Time", | ||
"America/Dawson": "Dawson, Yukon", | ||
"America/Chihuahua": "Chihuahua, La Paz, Mazatlan", | ||
"America/Phoenix": "Arizona", | ||
"America/Chicago": "Central Time", | ||
"America/Regina": "Saskatchewan", | ||
"America/Mexico_City": "Guadalajara, Mexico City, Monterrey", | ||
"America/Belize": "Central America", | ||
"America/Detroit": "Eastern Time", | ||
"America/Bogota": "Bogota, Lima, Quito", | ||
"America/Caracas": "Caracas, La Paz", | ||
"America/Santiago": "Santiago", | ||
"America/St_Johns": "Newfoundland and Labrador", | ||
"America/Sao_Paulo": "Brasilia", | ||
"America/Tijuana": "Tijuana", | ||
"America/Argentina/Buenos_Aires": "Buenos Aires, Georgetown", | ||
"America/Godthab": "Greenland", | ||
"America/Los_Angeles": "Pacific Time", | ||
"Atlantic/Azores": "Azores", | ||
"Atlantic/Cape_Verde": "Cape Verde Islands", | ||
GMT: "UTC", | ||
"Europe/London": "Edinburgh, London", | ||
"Europe/Dublin": "Dublin", | ||
"Europe/Lisbon": "Lisbon", | ||
"Africa/Casablanca": "Casablanca, Monrovia", | ||
"Atlantic/Canary": "Canary Islands", | ||
"Europe/Belgrade": "Belgrade, Bratislava, Budapest, Ljubljana, Prague", | ||
"Europe/Sarajevo": "Sarajevo, Skopje, Warsaw, Zagreb", | ||
"Europe/Brussels": "Brussels, Copenhagen, Madrid, Paris", | ||
"Europe/Amsterdam": "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna", | ||
"Africa/Algiers": "West Central Africa", | ||
"Europe/Bucharest": "Bucharest", | ||
"Africa/Cairo": "Cairo", | ||
"Europe/Helsinki": "Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius", | ||
"Europe/Athens": "Athens, Istanbul, Minsk", | ||
"Asia/Jerusalem": "Jerusalem", | ||
"Africa/Harare": "Harare, Pretoria", | ||
"Europe/Moscow": "Moscow, St. Petersburg, Volgograd", | ||
"Asia/Kuwait": "Kuwait, Riyadh", | ||
"Africa/Nairobi": "Nairobi", | ||
"Asia/Baghdad": "Baghdad", | ||
"Asia/Tehran": "Tehran", | ||
"Asia/Dubai": "Abu Dhabi, Muscat", | ||
"Asia/Baku": "Baku, Tbilisi, Yerevan", | ||
"Asia/Kabul": "Kabul", | ||
"Asia/Yekaterinburg": "Ekaterinburg", | ||
"Asia/Karachi": "Islamabad, Karachi, Tashkent", | ||
"Asia/Kolkata": "Chennai, Kolkata, Mumbai, New Delhi", | ||
"Asia/Kathmandu": "Kathmandu", | ||
"Asia/Dhaka": "Astana, Dhaka", | ||
"Asia/Colombo": "Sri Jayawardenepura", | ||
"Asia/Almaty": "Almaty, Novosibirsk", | ||
"Asia/Rangoon": "Yangon Rangoon", | ||
"Asia/Bangkok": "Bangkok, Hanoi, Jakarta", | ||
"Asia/Krasnoyarsk": "Krasnoyarsk", | ||
"Asia/Shanghai": "Beijing, Chongqing, Hong Kong SAR, Urumqi", | ||
"Asia/Kuala_Lumpur": "Kuala Lumpur, Singapore", | ||
"Asia/Taipei": "Taipei", | ||
"Australia/Perth": "Perth", | ||
"Asia/Irkutsk": "Irkutsk, Ulaanbaatar", | ||
"Asia/Seoul": "Seoul", | ||
"Asia/Tokyo": "Osaka, Sapporo, Tokyo", | ||
"Asia/Yakutsk": "Yakutsk", | ||
"Australia/Darwin": "Darwin", | ||
"Australia/Adelaide": "Adelaide", | ||
"Australia/Sydney": "Canberra, Melbourne, Sydney", | ||
"Australia/Brisbane": "Brisbane", | ||
"Australia/Hobart": "Hobart", | ||
"Asia/Vladivostok": "Vladivostok", | ||
"Pacific/Guam": "Guam, Port Moresby", | ||
"Asia/Magadan": "Magadan, Solomon Islands, New Caledonia", | ||
"Asia/Kamchatka": "Kamchatka, Marshall Islands", | ||
"Pacific/Fiji": "Fiji Islands", | ||
"Pacific/Auckland": "Auckland, Wellington", | ||
"Pacific/Tongatapu": "Nuku'alofa", | ||
}; | ||
@@ -90,3 +92,3 @@ export var LabelType; | ||
})(LabelType || (LabelType = {})); | ||
const TimezoneSelect = ({ value, onBlur, onChange, labelStyle = 'original', timezones = i18nTimezones, ...props }) => { | ||
const TimezoneSelect = ({ value, onBlur, onChange, labelStyle = "original", timezones = i18nTimezones, ...props }) => { | ||
const getOptions = React.useMemo(() => { | ||
@@ -98,3 +100,3 @@ return Object.entries(timezones) | ||
const tzStrings = informal.display(zone[0]); | ||
let label = ''; | ||
let label = ""; | ||
let abbrev = zone[0]; | ||
@@ -111,13 +113,13 @@ let altName = zone[0]; | ||
const min = tz.current.offset * 60; | ||
const hr = `${(min / 60) ^ 0}:` + (min % 60 === 0 ? '00' : Math.abs(min % 60)); | ||
const prefix = `(GMT${hr.includes('-') ? hr : `+${hr}`}) ${zone[1]}`; | ||
const hr = `${(min / 60) ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60)); | ||
const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`; | ||
switch (labelStyle) { | ||
case 'original': | ||
case "original": | ||
label = prefix; | ||
break; | ||
case 'altName': | ||
label = `${prefix} ${!altName.includes('/') ? `(${altName})` : ''}`; | ||
case "altName": | ||
label = `${prefix} ${!altName.includes("/") ? `(${altName})` : ""}`; | ||
break; | ||
case 'abbrev': | ||
label = `${prefix} ${abbrev.length < 5 ? `(${abbrev})` : ''}`; | ||
case "abbrev": | ||
label = `${prefix} ${abbrev.length < 5 ? `(${abbrev})` : ""}`; | ||
break; | ||
@@ -158,3 +160,3 @@ default: | ||
.toLowerCase() | ||
.indexOf(currentTime.tz.substr(currentTime.tz.indexOf('/') + 1)) !== -1) { | ||
.indexOf(currentTime.tz.substr(currentTime.tz.indexOf("/") + 1)) !== -1) { | ||
score += 8; | ||
@@ -164,3 +166,3 @@ } | ||
.toLowerCase() | ||
.indexOf(currentTime.tz.substr(currentTime.tz.indexOf('/') + 1)) !== -1) { | ||
.indexOf(currentTime.tz.substr(currentTime.tz.indexOf("/") + 1)) !== -1) { | ||
score += 4; | ||
@@ -170,3 +172,3 @@ } | ||
.toLowerCase() | ||
.indexOf(currentTime.tz.substr(0, currentTime.tz.indexOf('/')))) { | ||
.indexOf(currentTime.tz.substr(0, currentTime.tz.indexOf("/")))) { | ||
score += 2; | ||
@@ -176,3 +178,3 @@ } | ||
} | ||
else if (tz.value === 'GMT') { | ||
else if (tz.value === "GMT") { | ||
score += 1; | ||
@@ -186,7 +188,7 @@ } | ||
const parseTimezone = (zone) => { | ||
if (typeof zone === 'object' && zone.value && zone.label) | ||
if (typeof zone === "object" && zone.value && zone.label) | ||
return zone; | ||
if (typeof zone === 'string') { | ||
if (typeof zone === "string") { | ||
return (getOptions.find(tz => tz.value === zone) || | ||
(zone.indexOf('/') !== -1 && findFuzzyTz(zone))); | ||
(zone.indexOf("/") !== -1 && findFuzzyTz(zone))); | ||
} | ||
@@ -193,0 +195,0 @@ else if (zone.value && !zone.label) { |
{ | ||
"name": "react-timezone-select", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Usable, dynamic React Timezone Select", | ||
@@ -10,4 +10,5 @@ "main": "dist/index.js", | ||
"postpublish": "npm run build:example && npm run deploy", | ||
"build": "tsc --project ./tsconfig.json", | ||
"build": "tsc --project ./tsconfig.json && npm run copy-files", | ||
"build:example": "cd example && npm run build", | ||
"copy-files": "cp ./src/index.css ./dist", | ||
"deploy": "gh-pages -d example/build", | ||
@@ -14,0 +15,0 @@ "test": "jest", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24425
7
225