From 8f491b464719c6faa2e28240e377642b9aec13ac Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 13 Feb 2025 16:03:22 -0800 Subject: [PATCH] Polyfill: Fix handling of hour12/hourCycle to conform to spec The strategy of caching the output of DTF resolvedOptions() failed in the case of hour12/hourCycle, because those options are silently dropped if the chosen format does not include an hour component. Manually add them to the cached resolvedOptions object if the user included them. See: #3065 --- polyfill/lib/intl.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/polyfill/lib/intl.mjs b/polyfill/lib/intl.mjs index cb56addf0..4a186851b 100644 --- a/polyfill/lib/intl.mjs +++ b/polyfill/lib/intl.mjs @@ -137,6 +137,11 @@ function createDateTimeFormat(dtf, locale, options) { for (const prop in clonedResolved) { if (!ES.HasOwnProperty(options, prop)) delete clonedResolved[prop]; } + // hour12/hourCycle don't show up in resolvedOptions() unless the chosen + // format includes an hour component, so copy them explicitly in case they + // would otherwise be lost + clonedResolved.hour12 = options.hour12; + clonedResolved.hourCycle = options.hourCycle; SetSlot(dtf, OPTIONS, clonedResolved); } else { SetSlot(dtf, OPTIONS, options);