From ce0de180ee04fd262671c063e0d078c3607efe4e Mon Sep 17 00:00:00 2001 From: youdie006 Date: Sat, 10 Oct 2026 11:05:43 +0900 Subject: [PATCH] fix(fr): roll the end of an overnight time range into the next day FRSpecificTimeExpressionParser built the end of "22h00 - 02h00" on the start's day, so the range ended before it began. Move the end to the next day when it is earlier than the start, as the shared time expression parser does. --- .../fr/parsers/FRSpecificTimeExpressionParser.ts | 3 +++ test/fr/fr_time_exp.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/locales/fr/parsers/FRSpecificTimeExpressionParser.ts b/src/locales/fr/parsers/FRSpecificTimeExpressionParser.ts index 800832da5..298491b55 100644 --- a/src/locales/fr/parsers/FRSpecificTimeExpressionParser.ts +++ b/src/locales/fr/parsers/FRSpecificTimeExpressionParser.ts @@ -59,6 +59,9 @@ export default class FRSpecificTimeExpressionParser implements Parser { result.end = FRSpecificTimeExpressionParser.extractTimeComponent(result.start.clone(), secondMatch); if (result.end) { result.text += secondMatch[0]; + if (result.end.date().getTime() < result.start.date().getTime() && !result.end.isCertain("day")) { + result.end.addDurationAsImplied({ day: 1 }); + } } } diff --git a/test/fr/fr_time_exp.test.ts b/test/fr/fr_time_exp.test.ts index 6fe0c9feb..8057c1c09 100644 --- a/test/fr/fr_time_exp.test.ts +++ b/test/fr/fr_time_exp.test.ts @@ -199,6 +199,18 @@ test("Test - Single Expression", function () { expect(result.end).toBeDate(new Date(2012, 7, 10, 15, 0)); }); + testSingleCase(chrono.fr, "22h00 - 02h00", new Date(2012, 7, 10), (result) => { + expect(result.text).toBe("22h00 - 02h00"); + expect(result.start).toBeDate(new Date(2012, 7, 10, 22, 0)); + expect(result.end).toBeDate(new Date(2012, 7, 11, 2, 0)); + }); + + testSingleCase(chrono.fr, "22h à 2h", new Date(2012, 7, 31), (result) => { + expect(result.text).toBe("22h à 2h"); + expect(result.start).toBeDate(new Date(2012, 7, 31, 22, 0)); + expect(result.end).toBeDate(new Date(2012, 8, 1, 2, 0)); + }); + testSingleCase(chrono.fr, "13-15h", new Date(2012, 7, 10), (result) => { expect(result.index).toBe(0); expect(result.text).toBe("13-15h");