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
8 changes: 8 additions & 0 deletions src/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,12 @@ describe("parse", () => {
).toISOString()
).toBe("1989-12-19T07:30:10.000Z")
})
it("parses an ISO date whose year is before 1000", () => {
// Regression: the `four` helper padded to 2 digits, so a valid
// zero-padded year like "0087" produced an invalid ISO string and
// parse() threw instead of returning the date.
const d = parse("0087-06-15", "YYYY-MM-DD")
expect(Number.isNaN(+d)).toBe(false)
expect(d.getUTCFullYear()).toBe(87)
})
})
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const two = (n: number) => String(n).padStart(2, "0")
* Creates a leading zero string of 4 digits.
* @param n - A number.
*/
export const four = (n: number) => String(n).padStart(2, "0")
export const four = (n: number) => String(n).padStart(4, "0")

/**
* Normalizes a given part to NFKC.
Expand Down