Skip to content

Commit

Permalink
Prevent 24h time from being shortened
Browse files Browse the repository at this point in the history
  • Loading branch information
timolins committed Nov 16, 2023
1 parent f9554f6 commit c8ce66d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/format-date-range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ describe("format date range", () => {

test("format date range same day, different hours, with 24-hour locale", () => {
const from = new Date("2023-01-01T00:11:00.000Z");
const to = new Date("2023-01-01T14:30:59.999Z");
const to = new Date("2023-01-01T14:00:59.999Z");

expect(
formatDateRange(from, to, {
...defaultOptions,
locale: "en-GB",
})
).toBe("Jan 1, 0:11 - 14:30");
).toBe("Jan 1, 0:11 - 14:00");
});

test("format date range different days with time", () => {
Expand Down
4 changes: 3 additions & 1 deletion src/format-date-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {

const shortenAmPm = (text: string): string => {
const shortened = (text || "").replace(/ AM/g, "am").replace(/ PM/g, "pm");
const withoutDoubleZero = shortened.replace(/:00/g, "");
const withoutDoubleZero = shortened.includes("m")
? shortened.replace(/:00/g, "")
: shortened;
return withoutDoubleZero;
};

Expand Down

1 comment on commit c8ce66d

@emillinden
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious as to why we’re not shorting 24 time.

“00:11 - 14” would not be an uncommon pattern in a 24h locale. Neither would “09 - 14”.

Please sign in to comment.