Skip to content
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

[NoQA] perf: add patch for date-fns-tz which reduces the execution time of getDateTimeFormat by ~84% #48404

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions patches/date-fns-tz+2.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
diff --git a/node_modules/date-fns-tz/_lib/tzTokenizeDate/index.js b/node_modules/date-fns-tz/_lib/tzTokenizeDate/index.js
index 9222a61..8540224 100644
--- a/node_modules/date-fns-tz/_lib/tzTokenizeDate/index.js
+++ b/node_modules/date-fns-tz/_lib/tzTokenizeDate/index.js
@@ -59,20 +59,23 @@ function hackyOffset(dtf, date) {

var dtfCache = {};

+// New browsers use `hourCycle`, IE and Chrome <73 does not support it and uses `hour12`
+const testDateFormatted = new Intl.DateTimeFormat('en-US', {
+ hourCycle: 'h23',
+ timeZone: 'America/New_York',
+ year: 'numeric',
+ month: '2-digit',
+ day: '2-digit',
+ hour: '2-digit',
+ minute: '2-digit',
+ second: '2-digit',
+}).format(new Date('2014-06-25T04:00:00.123Z'))
+const hourCycleSupported =
+ testDateFormatted === '06/25/2014, 00:00:00' ||
+ testDateFormatted === '‎06‎/‎25‎/‎2014‎ ‎00‎:‎00‎:‎00'
+
function getDateTimeFormat(timeZone) {
if (!dtfCache[timeZone]) {
- // New browsers use `hourCycle`, IE and Chrome <73 does not support it and uses `hour12`
- var testDateFormatted = new Intl.DateTimeFormat('en-US', {
- hour12: false,
- timeZone: 'America/New_York',
- year: 'numeric',
- month: 'numeric',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit',
- second: '2-digit'
- }).format(new Date('2014-06-25T04:00:00.123Z'));
- var hourCycleSupported = testDateFormatted === '06/25/2014, 00:00:00' || testDateFormatted === '‎06‎/‎25‎/‎2014‎ ‎00‎:‎00‎:‎00';
dtfCache[timeZone] = hourCycleSupported ? new Intl.DateTimeFormat('en-US', {
hour12: false,
timeZone: timeZone,
diff --git a/node_modules/date-fns-tz/esm/_lib/tzTokenizeDate/index.js b/node_modules/date-fns-tz/esm/_lib/tzTokenizeDate/index.js
index cc1d143..17333cc 100644
--- a/node_modules/date-fns-tz/esm/_lib/tzTokenizeDate/index.js
+++ b/node_modules/date-fns-tz/esm/_lib/tzTokenizeDate/index.js
@@ -48,23 +48,24 @@ function hackyOffset(dtf, date) {
// to get deterministic local date/time output according to the `en-US` locale which
// can be used to extract local time parts as necessary.
var dtfCache = {}
+
+// New browsers use `hourCycle`, IE and Chrome <73 does not support it and uses `hour12`
+const testDateFormatted = new Intl.DateTimeFormat('en-US', {
+ hourCycle: 'h23',
+ timeZone: 'America/New_York',
+ year: 'numeric',
+ month: '2-digit',
+ day: '2-digit',
+ hour: '2-digit',
+ minute: '2-digit',
+ second: '2-digit',
+}).format(new Date('2014-06-25T04:00:00.123Z'))
+const hourCycleSupported =
+ testDateFormatted === '06/25/2014, 00:00:00' ||
+ testDateFormatted === '‎06‎/‎25‎/‎2014‎ ‎00‎:‎00‎:‎00'
+
function getDateTimeFormat(timeZone) {
if (!dtfCache[timeZone]) {
- // New browsers use `hourCycle`, IE and Chrome <73 does not support it and uses `hour12`
- var testDateFormatted = new Intl.DateTimeFormat('en-US', {
- hour12: false,
- timeZone: 'America/New_York',
- year: 'numeric',
- month: 'numeric',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit',
- second: '2-digit',
- }).format(new Date('2014-06-25T04:00:00.123Z'))
- var hourCycleSupported =
- testDateFormatted === '06/25/2014, 00:00:00' ||
- testDateFormatted === '‎06‎/‎25‎/‎2014‎ ‎00‎:‎00‎:‎00'
-
dtfCache[timeZone] = hourCycleSupported
? new Intl.DateTimeFormat('en-US', {
hour12: false,
Loading