Skip to content

Commit

Permalink
Polyfill: Fix handling of hour12/hourCycle to conform to spec
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptomato committed Feb 25, 2025
1 parent 60ef439 commit 8f491b4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions polyfill/lib/intl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8f491b4

Please sign in to comment.