Skip to content

Commit

Permalink
Merge pull request Expensify#48404 from callstack-internal/hur/perf/p…
Browse files Browse the repository at this point in the history
…atch-date-fns-tz

[NoQA] perf: add patch for date-fns-tz which reduces the execution time of getDateTimeFormat by ~84%
  • Loading branch information
mountiny authored Sep 9, 2024
2 parents b4d1cab + ad3fe7f commit 201dc52
Showing 1 changed file with 84 additions and 0 deletions.
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,

0 comments on commit 201dc52

Please sign in to comment.