From 14af2d2ee488e5793c84372b489437da91c2d5c0 Mon Sep 17 00:00:00 2001 From: Matthew Carr Date: Sat, 6 Jan 2024 11:35:11 -0600 Subject: [PATCH] changed to unit of of range reason --- src/impl/tokenParser.js | 5 +++-- test/datetime/tokenParse.test.js | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/impl/tokenParser.js b/src/impl/tokenParser.js index c7402fc2d..e2cf31fd2 100644 --- a/src/impl/tokenParser.js +++ b/src/impl/tokenParser.js @@ -455,11 +455,12 @@ export function explainFromTokens(locale, input, format) { matches["h"] > 12 && tokens.find((t) => t.val === "hh") ) { + const hourValue = matches["h"]; return { input, tokens, - invalidReason: "unparsable", - invalidExplanation: "Can't parse 24-hour time with meridiem", + invalidReason: "unit out of range", + invalidExplanation: `you specified ${hourValue} (of type ${typeof hourValue}) as an hour along with a meridiem, which is invalid`, }; } return { input, tokens, regex, rawMatches, matches, result, zone, specificOffset }; diff --git a/test/datetime/tokenParse.test.js b/test/datetime/tokenParse.test.js index 85fcfc8b2..2e45e548c 100644 --- a/test/datetime/tokenParse.test.js +++ b/test/datetime/tokenParse.test.js @@ -21,8 +21,10 @@ test("DateTime.fromFormat() parses basic times", () => { test("DateTime.fromFormat() yields Invalid reason for invalid input", () => { const i = DateTime.fromFormat("11-08-2023 15:00 AM", "MM-dd-yyyy hh:mm a"); expect(i.invalid).not.toBeNull(); - expect(i.invalid.reason).toEqual("unparsable"); - expect(i.invalid.explanation).toEqual("Can't parse 24-hour time with meridiem"); + expect(i.invalid.reason).toEqual("unit out of range"); + expect(i.invalid.explanation).toEqual( + "you specified 15 (of type number) as an hour along with a meridiem, which is invalid" + ); }); test("DateTime.fromFormat() throws ConflictingSpecificationError for invalid format", () => {