@brightspace-ui/intl
Advanced tools
Comparing version 3.1.2 to 3.1.3
@@ -6,8 +6,8 @@ import { getDocumentLocaleSettings, getLanguage, merge } from './common.js'; | ||
// leaving out the following since do not throw and have multiple possible offsets: AMT, AST, BST, CDT, CST, ECT, GST, IST, LHST, MST, PST, SST | ||
// timezone abbreviations and offsets from https://www.timeanddate.com/time/zones/ | ||
const timezoneOffsetMap = { | ||
'ACDT': '+1030', | ||
'ACST': '+0930', | ||
'ACT': '-0500', | ||
'ACWST': '+0845', | ||
'ADT': '-0300', | ||
'AEDT': '+1100', | ||
@@ -20,19 +20,28 @@ 'AEST': '+1000', | ||
'ALMT': '+0600', | ||
'AMST': '-0300', | ||
'ANAST': '+1200', | ||
'ANAT': '+1200', | ||
'AQTT': '+0500', | ||
'ART': '-0300', | ||
'AWDT': '+0900', | ||
'AWST': '+0800', | ||
'AZODT': '+0000', | ||
'AZOST': '+0000', | ||
'AZOT': '-0100', | ||
'AZST': '+0500', | ||
'AZT': '+0400', | ||
'BDT': '+0800', | ||
'B': '+0200', | ||
'BDST': '+0100', | ||
'BIOT': '+0600', | ||
'BIT': '-1200', | ||
'BNT': '+0800', | ||
'BOT': '-0400', | ||
'BRST': '-0200', | ||
'BRT': '-0300', | ||
'BT': '-0300', | ||
'BTT': '+0600', | ||
'C': '+0300', | ||
'CAST': '+0800', | ||
'CAT': '+0200', | ||
'CCT': '+0630', | ||
'CEDT': '+0200', | ||
'CEST': '+0200', | ||
@@ -43,8 +52,12 @@ 'CET': '+0100', | ||
'CHOT': '+0800', | ||
'CHODT': '+0900', | ||
'CHODST': '+0900', | ||
'CHOST': '+0900', | ||
'CHST': '+1000', | ||
'CHUT': '+1000', | ||
'CIST': '-0800', | ||
'CIT': '+0800', | ||
'CIDST': '-0400', | ||
'CIST': '-0500', | ||
'CIT': '-0500', | ||
'CKT': '-1000', | ||
'CLDT': '-0300', | ||
'CLST': '-0300', | ||
@@ -54,24 +67,34 @@ 'CLT': '-0400', | ||
'COT': '-0500', | ||
'CT': '+0800', | ||
'CT': '-0600', | ||
'CVT': '-0100', | ||
'CWST': '+0845', | ||
'CXT': '+0700', | ||
'D': '+0400', | ||
'DAVT': '+0700', | ||
'DDUT': '+1000', | ||
'DFT': '+0100', | ||
'E': '+0500', | ||
'EADT': '-0500', | ||
'EASST': '-0500', | ||
'EAST': '-0600', | ||
'EAT': '+0300', | ||
'EDT': '-0400', | ||
'ECST': '+0200', | ||
'EEDT': '+0300', | ||
'EEST': '+0300', | ||
'EET': '+0200', | ||
'EFATE': '+1100', | ||
'EGST': '+0000', | ||
'EGT': '-0100', | ||
'EIT': '+0900', | ||
'EST': '-0500', | ||
'ET': '-0500', | ||
'F': '+0600', | ||
'FET': '+0300', | ||
'FJDT': '+1300', | ||
'FJST': '+1300', | ||
'FJT': '+1200', | ||
'FKDT': '-0300', | ||
'FKST': '-0300', | ||
'FKT': '-0400', | ||
'FNT': '-0200', | ||
'G': '+0700', | ||
'GALT': '-0600', | ||
@@ -84,30 +107,64 @@ 'GAMT': '-0900', | ||
'GMT': '+0000', | ||
'GT': '+0000', | ||
'GYT': '-0400', | ||
'HAC': '-0500', | ||
'HAR': '-0600', | ||
'HNA': '-0400', | ||
'HNC': '-0600', | ||
'HNP': '-0800', | ||
'HNR': '-0700', | ||
'H': '+0800', | ||
'HAA': '-0300', | ||
'HADT': '-0900', | ||
'HAE': '-0400', | ||
'HAEC': '+0200', | ||
'HAP': '-0700', | ||
'HAST': '-1000', | ||
'HAT': '-0230', | ||
'HDT': '-0900', | ||
'HAEC': '+0200', | ||
'HST': '-1000', | ||
'HKT': '+0800', | ||
'HLV': '-0400', | ||
'HMT': '+0500', | ||
'HNE': '-0500', | ||
'HNT': '-0330', | ||
'HOVDT': '+0800', | ||
'HOVDST': '+0800', | ||
'HOVST': '+0800', | ||
'HOVT': '+0700', | ||
'HST': '-1000', | ||
'I': '+0900', | ||
'ICT': '+0700', | ||
'IDLW': '-1200', | ||
'IDT': '+0300', | ||
'IOT': '+0300', | ||
'IOT': '+0600', | ||
'IRDT': '+0430', | ||
'IRKST': '+0900', | ||
'IRKT': '+0800', | ||
'IRST': '+0330', | ||
'JST': '+0900', | ||
'K': '+1000', | ||
'KALT': '+0200', | ||
'KGT': '+0600', | ||
'KIT': '+0500', | ||
'KOST': '+1100', | ||
'KRAST': '+0800', | ||
'KRAT': '+0700', | ||
'KST': '+0900', | ||
'KT': '+0900', | ||
'KUYT': '+0400', | ||
'L': '+1100', | ||
'LHDT': '+1100', | ||
'LHST': '+1030', | ||
'LINT': '+1400', | ||
'MAGT': '+1200', | ||
'M': '+1200', | ||
'MAGST': '+1200', | ||
'MAGT': '+1100', | ||
'MART': '-0930', | ||
'MAWT': '+0500', | ||
'MCK': '+0300', | ||
'MEST': '+0200', | ||
'MESZ': '+0200', | ||
'MET': '+0100', | ||
'MEZ': '+0100', | ||
'MDST': '-0600', | ||
'MDT': '-0600', | ||
'MET': '+0100', | ||
'MEST': '+0200', | ||
'MHT': '+1200', | ||
@@ -117,11 +174,25 @@ 'MIST': '+1100', | ||
'MMT': '+0630', | ||
'MSD': '+0400', | ||
'MSK': '+0300', | ||
'MT': '-0700', | ||
'MUT': '+0400', | ||
'MVT': '+0500', | ||
'MYT': '+0800', | ||
'N': '-0100', | ||
'NACDT': '-0500', | ||
'NACST': '-0600', | ||
'NAEDT': '-0400', | ||
'NAEST': '-0500', | ||
'NAMDT': '-0600', | ||
'NAMST': '-0700', | ||
'NAPDT': '-0700', | ||
'NAPST': '-0800', | ||
'NCT': '+1100', | ||
'NDT': '-0230', | ||
'NFDT': '+1200', | ||
'NFT': '+1100', | ||
'NOVST': '+0700', | ||
'NOVT': '+0700', | ||
'NPT': '+0545', | ||
'NRT': '+1200', | ||
'NST': '-0330', | ||
@@ -132,6 +203,12 @@ 'NT': '-0330', | ||
'NZST': '+1200', | ||
'O': '-0200', | ||
'OESZ': '+0300', | ||
'OEZ': '+0200', | ||
'OMSST': '+0700', | ||
'OMST': '+0600', | ||
'ORAT': '+0500', | ||
'PDST': '-0700', | ||
'PDT': '-0700', | ||
'PET': '-0500', | ||
'PETST': '+1200', | ||
'PETT': '+1200', | ||
@@ -145,7 +222,12 @@ 'PGT': '+1000', | ||
'PONT': '+1100', | ||
'PYST': '-0300', | ||
'PYT': '-0400', | ||
'PT': '-0800', | ||
'PWT': '+0900', | ||
'Q': '-0400', | ||
'QYZT': '+0600', | ||
'R': '-0500', | ||
'RET': '+0400', | ||
'ROTT': '-0300', | ||
'S': '-0600', | ||
'SAKT': '+1100', | ||
'SAMST': '+0400', | ||
'SAMT': '+0400', | ||
@@ -160,3 +242,5 @@ 'SAST': '+0200', | ||
'SRT': '-0300', | ||
'ST': '+1400', | ||
'SYOT': '+0300', | ||
'T': '-0700', | ||
'TAHT': '-1000', | ||
@@ -169,5 +253,7 @@ 'THA': '+0700', | ||
'TMT': '+0500', | ||
'TOST': '+1400', | ||
'TOT': '+1300', | ||
'TRT': '+0300', | ||
'TOT': '+1300', | ||
'TVT': '+1200', | ||
'U': '-0800', | ||
'ULAST': '+0900', | ||
@@ -179,3 +265,5 @@ 'ULAT': '+0800', | ||
'UZT': '+0500', | ||
'V': '-0900', | ||
'VET': '-0400', | ||
'VLAST': '+1100', | ||
'VLAT': '+1000', | ||
@@ -185,13 +273,27 @@ 'VOLT': '+0400', | ||
'VUT': '+1100', | ||
'W': '-1000', | ||
'WAKT': '+1200', | ||
'WARST': '-0300', | ||
'WAST': '+0200', | ||
'WAT': '+0100', | ||
'WDT': '+0900', | ||
'WEDT': '+0100', | ||
'WEST': '+0100', | ||
'WESZ': '+0100', | ||
'WET': '+0000', | ||
'WIT': '+0700', | ||
'WEZ': '+0000', | ||
'WFT': '+1200', | ||
'WGST': '-0200', | ||
'WGT': '-0300', | ||
'WST': '+0800', | ||
'WIB': '+0700', | ||
'WIT': '+0900', | ||
'WITA': '+0800', | ||
'WT': '+0000', | ||
'X': '-1100', | ||
'Y': '-1200', | ||
'YAKST': '+1000', | ||
'YAKT': '+0900', | ||
'YEKT': '+0500' | ||
'YAPT': '+1000', | ||
'YEKST': '+0600', | ||
'YEKT': '+0500', | ||
'Z': '+0000' | ||
}; | ||
@@ -231,7 +333,8 @@ | ||
if (timezone.includes('-') || timezone.includes('+')) { | ||
const re = /([A-Z]{3})(\+|-)([0-9]{1,2}):([0-9]{2})/; | ||
const re = /([A-Z]{3})?(\+|-)([0-9]{1,2})(:)?([0-9]{2})?/; | ||
const match = timezone.match(re); | ||
if (match && match.length === 5) { | ||
if (match && match.length === 6) { | ||
// YYYY-MM-DDTHH:mm:ss(+|-)HH:MM | ||
dateString = `${date.year}-${date.month}-${date.date}T${date.hours}:${date.minutes}:${date.seconds}${match[2]}${prePadByZero(match[3], 2)}:${prePadByZero(match[4], 2)}`; | ||
const mins = match[5] ? prePadByZero(match[5], 2) : '00'; | ||
dateString = `${date.year}-${date.month}-${date.date}T${date.hours}:${date.minutes}:${date.seconds}${match[2]}${prePadByZero(match[3], 2)}:${mins}`; | ||
} | ||
@@ -242,2 +345,143 @@ } | ||
function getTimezoneFromDuplicatedAbbreviation(abbrTimezone) { | ||
const longTimezone = getDocumentLocaleSettings().timezone.identifier; | ||
switch (abbrTimezone) { | ||
case 'ADST': | ||
// Alaska Daylight Saving Time -0800 (America/Anchorage, America/Juneau, America/Nome, America/Sitka, America/Yakutat) | ||
// Atlantic Daylight Saving TIme -0300 (America) | ||
if (longTimezone === 'America/Anchorage' | ||
|| longTimezone === 'America/Juneau' | ||
|| longTimezone === 'America/Nome' | ||
|| longTimezone === 'America/Sitka' | ||
|| longTimezone === 'America/Yakutat' | ||
) { | ||
return '-0800'; | ||
} else return '-0300'; | ||
case 'ADT': | ||
// Arabia Daylight Time +0400 (Asia) | ||
// Atlantic Daylight Time -0300 (America) | ||
return longTimezone.includes('America') ? '-0300' : '+0400'; | ||
case 'AMT': | ||
// Amazon Time (Brazil) -0400 (America) | ||
// Armenia Time +0400 (Asia) | ||
return longTimezone.includes('America') ? '-0400' : '+0400'; | ||
case 'AMST': | ||
// Amazon Summer Time -0300 (America) | ||
// Armenia Summer Time +0500 (Asia) | ||
return longTimezone.includes('America') ? '-0300' : '+0500'; | ||
case 'AST': | ||
// Atlantic Standard Time -0400 (America) | ||
// Arabia Standard Time +0300 (Asia) | ||
return longTimezone.includes('America') ? '-0400' : '+0300'; | ||
case 'AT': | ||
// Alaska Time -0900 (America/Anchorage, America/Juneau, America/Nome, America/Sitka, America/Yakutat) | ||
// Atlantic Time -0400 (America) | ||
if (longTimezone === 'America/Anchorage' | ||
|| longTimezone === 'America/Juneau' | ||
|| longTimezone === 'America/Nome' | ||
|| longTimezone === 'America/Sitka' | ||
|| longTimezone === 'America/Yakutat' | ||
) { | ||
return '-0900'; | ||
} else return '-0400'; | ||
case 'BDT': | ||
// British Daylight Time +0100 (Europe) | ||
// Brunei Time +0800 | ||
return longTimezone.includes('Europe') ? '+0100' : '+0800'; | ||
case 'BST': | ||
// Bangladesh Standard Time +0600 (Asia) | ||
// British Summer Time +0100 (Europe) | ||
// Bougainville Standard Time +1100 (Pacific) | ||
// Brazilian Summer Time -0200 (America) | ||
if (longTimezone.includes('Asia')) return '+0600'; | ||
else if (longTimezone.includes('Pacific')) return '+1100'; | ||
else if (longTimezone.includes('America')) return '-0200'; | ||
else return '+0100'; | ||
case 'CDST': | ||
// Central Daylight Savings Time +1030 (Australia) | ||
// Central Daylight Saving Time -0500 (America) | ||
return longTimezone.includes('America') ? '-0500' : '+1030'; | ||
case 'CDT': | ||
// Central Daylight Time -0500 (America) | ||
// Cuba Daylight Time -0400 (America/Havana) | ||
// Central Daylight Time +1030 (Australia) | ||
if (longTimezone === 'America/Havana') return '-0400'; | ||
else if (longTimezone.includes('America')) return '-0500'; | ||
else return '+1030'; | ||
case 'CST': | ||
// Cuba Standard Time -0500 (America/Havana) | ||
// Central Standard Time -0600 (America) | ||
// China Standard Time +0800 (Asia) | ||
// Australian Central Standard Time +0930 (Australia) | ||
if (longTimezone === 'America/Havana') return '-0500'; | ||
else if (longTimezone.includes('America')) return '-0600'; | ||
else if (longTimezone.includes('Australia')) return '+0930'; | ||
else return '+0800'; | ||
case 'ECT': | ||
// European Central Time +0100 (Europe, Africa) | ||
// Ecuador Time -0500 (America) | ||
return longTimezone.includes('America') ? '-0500' : '+0100'; | ||
case 'EDT': | ||
case 'EDST': | ||
// Eastern Daylight Time +1100 (Australia) | ||
// Eastern Daylight Time -0400 (America) | ||
return longTimezone.includes('America') ? '-0400' : '+1100'; | ||
case 'EST': | ||
// Eastern Standard Time +1000 (Australia) | ||
// Eastern Standard Time -0500 (America) | ||
return longTimezone.includes('America') ? '-0500' : '+1000'; | ||
case 'GST': | ||
// South Georgia and the South Sandwich Islands Time -0200 (Atlantic) | ||
// Gulf Standard Time +0400 (Asia) | ||
// Guam Standard Time +1000 (Pacific) | ||
if (longTimezone.includes('Atlantic')) return '-0200'; | ||
else if (longTimezone.includes('Pacific')) return '+1000'; | ||
else return '+0400'; | ||
case 'IDT': | ||
// Iran Daylight Time +0430 (Asia/Tehran) | ||
// Israel Daylight Time +0300 (Asia) | ||
return longTimezone === 'Asia/Tehran' ? '+0430' : '+0300'; | ||
case 'IST': | ||
// Indian Standard Time +0530 (Asia/Calcutta & Asia/Colombo) | ||
// Irish Standard Time +0100 (Europe) | ||
// Israel Standard Time +0200 (Asia) | ||
if (longTimezone === 'Asia/Calcutta' || longTimezone === 'Asia/Colombo') return '+0530'; | ||
else if (longTimezone.includes('Asia')) return '+0200'; | ||
else return '+0100'; | ||
case 'MST': | ||
// Malaysia Standard Time +0800 (Asia) | ||
// Mountain Standard Time -0700 (America) | ||
return longTimezone.includes('America') ? '-0700' : '+0800'; | ||
case 'PST': | ||
// Pacific Standard Time -0800 (America) | ||
// Philippine Standard Time +0800 (Asia) | ||
return longTimezone.includes('America') ? '-0800' : '+0800'; | ||
case 'PYST': | ||
// Pyongyan Time +0830 (Asia) | ||
// Paraguay Summer Time -0300 (America) | ||
return longTimezone.includes('Asia') ? '+0830' : '-0300'; | ||
case 'PYT': | ||
// Paraguary Time -0400 (South America) | ||
// Pyongyan Time +0830 (Asia) | ||
return longTimezone.includes('Asia') ? '+0830' : '-0400'; | ||
case 'SST': | ||
// Singapore Standard Time +0800 (Asia) | ||
// Samoa Standard Time -1100 (Pacific) | ||
return longTimezone.includes('Pacific') ? '-1100' : '+0800'; | ||
case 'WAT': | ||
// West Africa Time +0100 (Africa) | ||
// Western Australia Time +0800 (Australia) | ||
return longTimezone.includes('Australia') ? '+0800' : '+0100'; | ||
case 'WST': | ||
// West Samoa Time +1400 (Pacific) | ||
// Western Sahara Summer Time +0100 (Africa) | ||
// Western Standard Time +0800 (Australia) | ||
if (longTimezone.includes('Pacific')) return '+1400'; | ||
else if (longTimezone.includes('Australia')) return '+0800'; | ||
else return '+0100'; | ||
default: | ||
throw new Error(`Invalid timezone: unable to retrieve timezone offset for ${longTimezone}`); | ||
} | ||
} | ||
function getParts() { | ||
@@ -431,3 +675,3 @@ | ||
if (isNaN(parsedDateString.getTime())) { | ||
timezone = timezoneOffsetMap[timezone]; | ||
timezone = timezoneOffsetMap[timezone] || getTimezoneFromDuplicatedAbbreviation(timezone); | ||
dateString = getDateStringWithTimezone(datePrePad, timezone); | ||
@@ -442,3 +686,3 @@ parsedDateString = new Date(Date.parse(dateString)); | ||
if (isNaN(utcCorrectedDate.getTime())) { | ||
utcCorrectedTimezone = timezoneOffsetMap[utcCorrectedTimezone]; | ||
utcCorrectedTimezone = timezoneOffsetMap[utcCorrectedTimezone] || getTimezoneFromDuplicatedAbbreviation(utcCorrectedTimezone); | ||
dateStringInTimezone = getDateStringWithTimezone(datePrePad, utcCorrectedTimezone); | ||
@@ -445,0 +689,0 @@ utcCorrectedDate = new Date(Date.parse(dateStringInTimezone)); |
{ | ||
"name": "@brightspace-ui/intl", | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"description": "Internationalization APIs for number, date, time and file size formatting and parsing in D2L Brightspace.", | ||
@@ -5,0 +5,0 @@ "main": "lib/number.js", |
@@ -5,3 +5,2 @@ # intl | ||
[![NPM downloads](https://img.shields.io/npm/dt/@brightspace-ui/intl.svg)](https://www.npmjs.com/package/@brightspace-ui/intl) | ||
![Build status](https://github.com/BrightspaceUI/intl/workflows/CI/badge.svg) | ||
@@ -8,0 +7,0 @@ ## Overview |
66160
1531
223