From ad3fe7fc7d0b26a07e6a661978e6dd52e22a4424 Mon Sep 17 00:00:00 2001 From: hurali97 Date: Mon, 2 Sep 2024 17:31:11 +0500 Subject: [PATCH] perf: add patch for date-fns-tz which reduces the execution time of getDateTimeFormat by ~84% --- patches/date-fns-tz+2.0.0.patch | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 patches/date-fns-tz+2.0.0.patch diff --git a/patches/date-fns-tz+2.0.0.patch b/patches/date-fns-tz+2.0.0.patch new file mode 100644 index 000000000000..aa88f1443a79 --- /dev/null +++ b/patches/date-fns-tz+2.0.0.patch @@ -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,