Skip to content

Commit

Permalink
changed to unit of of range reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Carr committed Jan 6, 2024
1 parent 429c38e commit 14af2d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/impl/tokenParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
6 changes: 4 additions & 2 deletions test/datetime/tokenParse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 14af2d2

Please sign in to comment.