-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DateTimeFormat
polyfills with timezone abbreviations
#31074
Changes from 14 commits
a1021fd
4653beb
edd9965
3d3b41a
aec6871
78b0022
1e6909a
7300104
8658f99
ba1a2d7
f9afabe
2c52e0c
d1feb9e
5242683
c597f1d
b207560
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type {DateTimeFormatConstructor} from '@formatjs/intl-datetimeformat'; | ||
import DateUtils from '@libs/DateUtils'; | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
const tzLinks: Record<string, string> = { | ||
'Africa/Abidjan': 'Africa/Accra', | ||
CET: 'Europe/Paris', | ||
CST6CDT: 'America/Chicago', | ||
EET: 'Europe/Sofia', | ||
EST: 'America/Cancun', | ||
EST5EDT: 'America/New_York', | ||
'Etc/GMT': 'UTC', | ||
'Etc/UTC': 'UTC', | ||
Factory: 'UTC', | ||
GMT: 'UTC', | ||
HST: 'Pacific/Honolulu', | ||
MET: 'Europe/Paris', | ||
MST: 'America/Phoenix', | ||
MST7MDT: 'America/Denver', | ||
PST8PDT: 'America/Los_Angeles', | ||
WET: 'Europe/Lisbon', | ||
}; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
export default function () { | ||
// Because JS Engines do not expose default timezone, the polyfill cannot detect local timezone that a browser is in. | ||
// We must manually do this by getting the local timezone before adding polyfill. | ||
let currentTimezone = DateUtils.getCurrentTimezone().selected as string; | ||
if (currentTimezone in tzLinks) { | ||
currentTimezone = tzLinks[currentTimezone]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we reuse There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated! |
||
|
||
require('@formatjs/intl-datetimeformat/polyfill-force'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tienifr Can you address this comment: #34035 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have replied on the other issue #34035 (comment) |
||
require('@formatjs/intl-datetimeformat/locale-data/en'); | ||
require('@formatjs/intl-datetimeformat/locale-data/es'); | ||
require('@formatjs/intl-datetimeformat/add-all-tz'); | ||
|
||
if ('__setDefaultTimeZone' in Intl.DateTimeFormat) { | ||
// eslint-disable-next-line no-underscore-dangle | ||
(Intl.DateTimeFormat as DateTimeFormatConstructor).__setDefaultTimeZone(currentTimezone); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean
eslint-enable
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tienifr Friendly bump! Maybe I am missing something haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! I've updated.