-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Description
🐞 bug report
Affected Package
The issue is caused by package @angular/common (locales/extra).
Is this a regression?
This does not appear to be a regression.
Description
If you try to use formatDate
with the "B" placeholder ("at night", "in the morning", etc.), this does not work for locale "en" (and sublocales) between 21:00 and 06:00. Instead of getting "at night", you'll get "AM/PM".
This is caused by a misinterpretation of the time rule ['23:00', '06:00']
in @angular/common/locales/extra/en*.ts
, as it will never match:
angular/packages/common/src/i18n/format_date.ts
Lines 286 to 290 in fee3161
if (currentHours >= hoursFrom && currentMinutes >= minutesFrom && | |
(currentHours < hoursTo || | |
(currentHours === hoursTo && currentMinutes < minutesTo))) { | |
result = dayPeriods[index]; | |
} |
This will happen for any rule that straddles midnight (although a quick glance only shows English to be affected).
🔬 Minimal Reproduction
formatDate('2018-06-27T04:23:00', 'h B', 'en') + ', ' + formatDate('2018-06-27T06:23:00', 'h B', 'en')
Expected: 4 at night, 6 in the morning
, actual: 4 AM, 6 in the morning
.
Compared to Dutch: 4 's nachts, 6 's ochtends
(not 4 a.m., 6 's ochtends
).
🌍 Your Environment
Angular Version:
Angular 6–9