1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:27:43 +00:00

LibJS+LibUnicode: Handle flexible day periods that roll over midnight

When searching for the locale-specific flexible day period for a given
hour, we were neglecting to handle cases where the period crosses 00:00.
For example, the en locale defines a day period range of [21:00, 06:00).
When given the hour of 05:00, we were checking if (21 <= 5 && 5 < 6),
thus not recognizing that the hour falls in that period.
This commit is contained in:
Timothy Flynn 2022-01-05 08:24:02 -05:00 committed by Linus Groh
parent c8addf1a5e
commit ec7d5351ed
2 changed files with 16 additions and 2 deletions

View file

@ -261,6 +261,14 @@ describe("dayPeriod", () => {
expect(as.format(d1)).toBe(d.as1);
});
});
test("flexible day period rolls over midnight", () => {
// For the en locale, this time (05:00) falls in the flexible day period range of [21:00, 06:00).
const date = Date.UTC(2017, 11, 12, 5, 0, 0, 0);
const en = new Intl.DateTimeFormat("en", { dayPeriod: "short", timeZone: "UTC" });
expect(en.format(date)).toBe("5 at night");
});
});
describe("hour", () => {