Skip to content

Commit

Permalink
Polyfill: Fix formatting PlainDateTime with both dateStyle and timeStyle
Browse files Browse the repository at this point in the history
Adjusting the options to not print the time zone name in timeStyle long or
full (#2795) inadvertently regressed formatting a PlainDateTime with both
dateStyle and timeStyle specified.

See: #3061
  • Loading branch information
ptomato committed Feb 25, 2025
1 parent c1c7e07 commit 726becd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions polyfill/lib/intl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,19 @@ function datetimeAmend(originalOptions) {
// Try to fake what timeStyle should do if not printing the time zone name
delete options.timeStyle;
ObjectAssign(options, { hour: 'numeric', minute: '2-digit', second: '2-digit' });

// If moving to a fake timeStyle while dateStyle is present, we also have to
// move to a fake dateStyle. dateStyle is mutually exclusive with hour etc.
if (options.dateStyle) {
const dateStyleHacks = {
short: { year: 'numeric', month: 'numeric', day: 'numeric' },
medium: { year: 'numeric', month: 'short', day: 'numeric' },
long: { year: 'numeric', month: 'long', day: 'numeric' },
full: { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' }
};
ObjectAssign(options, dateStyleHacks[options.dateStyle]);
delete options.dateStyle;
}
}
if (!hasTimeOptions(options) && !hasDateOptions(options)) {
if (hasAnyDateTimeOptions(originalOptions)) {
Expand Down

0 comments on commit 726becd

Please sign in to comment.