-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48404 from callstack-internal/hur/perf/patch-date…
…-fns-tz [NoQA] perf: add patch for date-fns-tz which reduces the execution time of getDateTimeFormat by ~84%
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |