Skip to content

Commit

Permalink
add: dedicated tests for padding in formatTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitsunee committed Nov 23, 2024
1 parent 62be0b6 commit 3f4fab7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/formatTime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { formatTime } from "../src/formatTime";
import { getLocalTimezone } from "./utils/getLocalTimezone";

const localTz = getLocalTimezone();
const sampleDate = new Date(`2024-11-23T00:17:32.123${localTz}`);
const sampleDate = new Date(`2024-11-23T00:17:32.023${localTz}`);

console.log(
`Created sample time with offset ${localTz}:
Local: ${sampleDate.toLocaleString()}
UTC: ${sampleDate.toLocaleString(undefined, { timeZone: "UTC" })}`
UTC: ${sampleDate.toLocaleString(undefined, { timeZone: "UTC" })}\n`
);

test("basic date variables", () => {
Expand All @@ -25,6 +25,19 @@ test("basic date variables", () => {
);
});

test("padding", () => {
assert.is(
formatTime("%ms%", sampleDate, false, 24),
"23",
"test unpadded %ms%"
);
assert.is(
formatTime("%#ms%", sampleDate, false, 24),
"023",
"test padded %ms%"
);
});

test("12hour notation", () => {
assert.is(
formatTime("%time%", sampleDate, false, 12),
Expand Down

0 comments on commit 3f4fab7

Please sign in to comment.