Skip to content

Commit

Permalink
fix: fix 12 am parsed as noon
Browse files Browse the repository at this point in the history
Resolves #461, resolves #522
  • Loading branch information
ivan-lednev committed Sep 28, 2024
1 parent ad4b7f7 commit 97d735c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/parser/timestamp/timestamp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ it.each([
["3PM", { hours: 15, minutes: 0 }],
["11 PM ", { hours: 23, minutes: 0 }],
["0301PM", { hours: 15, minutes: 1 }],
["12:30am", { hours: 0, minutes: 30 }],
])("Parses timestamp %s", (asText, object) => {
expect(parseTimestamp(asText, moment()).toObject()).toMatchObject(object);
});
4 changes: 4 additions & 0 deletions src/parser/timestamp/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function parseTimestamp(asText: string, day: Moment) {
parsedHours += 12;
}

if (ampm?.toLowerCase().trim() === "am" && parsedHours === 12) {
parsedHours = 0;
}

const timeOfDay = window.moment.duration({
hours: parsedHours,
minutes: parsedMinutes,
Expand Down

0 comments on commit 97d735c

Please sign in to comment.