Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions test/datetime/tokenParse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ test("DateTime.fromFormat() throws if you specify meridiem with 24-hour time", (
expect(() => DateTime.fromFormat("930PM", "Hmma")).toThrow(ConflictingSpecificationError);
});

test("DateTime.fromFormat() throws if h is used with 24-hour time", () => {
expect(() => DateTime.fromFormat("18:30 AM", "h:mm a")).toThrowError(
ConflictingSpecificationError
);
});

// #714
test("DateTime.fromFormat() makes dots optional and handles non breakable spaces", () => {
function parseMeridiem(input, isAM) {
Expand Down