Skip to content

Commit 726becd

Browse files
committed
Polyfill: Fix formatting PlainDateTime with both dateStyle and timeStyle
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
1 parent c1c7e07 commit 726becd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

polyfill/lib/intl.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,19 @@ function datetimeAmend(originalOptions) {
472472
// Try to fake what timeStyle should do if not printing the time zone name
473473
delete options.timeStyle;
474474
ObjectAssign(options, { hour: 'numeric', minute: '2-digit', second: '2-digit' });
475+
476+
// If moving to a fake timeStyle while dateStyle is present, we also have to
477+
// move to a fake dateStyle. dateStyle is mutually exclusive with hour etc.
478+
if (options.dateStyle) {
479+
const dateStyleHacks = {
480+
short: { year: 'numeric', month: 'numeric', day: 'numeric' },
481+
medium: { year: 'numeric', month: 'short', day: 'numeric' },
482+
long: { year: 'numeric', month: 'long', day: 'numeric' },
483+
full: { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' }
484+
};
485+
ObjectAssign(options, dateStyleHacks[options.dateStyle]);
486+
delete options.dateStyle;
487+
}
475488
}
476489
if (!hasTimeOptions(options) && !hasDateOptions(options)) {
477490
if (hasAnyDateTimeOptions(originalOptions)) {

0 commit comments

Comments
 (0)