Skip to content

Commit

Permalink
add error handle when going over 12 when specifying 12-hour format
Browse files Browse the repository at this point in the history
  • Loading branch information
Sho-ki committed May 16, 2024
1 parent cafc4ee commit d35be5a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/impl/tokenParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,13 @@ export class TokenParser {
if (!this.isValid) {
return { input, tokens: this.tokens, invalidReason: this.invalidReason };
} else {
const [rawMatches, matches] = match(input, this.regex, this.handlers),
[result, zone, specificOffset] = matches
? dateTimeFromMatches(matches)
: [null, null, undefined];
const [rawMatches, matches] = match(input, this.regex, this.handlers);
if (hasOwnProperty(matches, "h") && matches.h > 12) {
throw new ConflictingSpecificationError("Can't go over 12 when specifying 12-hour format");
}
const [result, zone, specificOffset] = matches
? dateTimeFromMatches(matches)
: [null, null, undefined];
if (hasOwnProperty(matches, "a") && hasOwnProperty(matches, "H")) {
throw new ConflictingSpecificationError(
"Can't include meridiem when specifying 24-hour format"
Expand Down

0 comments on commit d35be5a

Please sign in to comment.