Skip to content

Commit

Permalink
Add some tests for 'YYYY' format
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharparam committed Feb 11, 2023
1 parent 37dbef2 commit ea97f4c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/display.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,15 @@ it('As JSON -> toJSON', () => {
it('As ISO 8601 String -> toISOString e.g. 2013-02-04T22:44:30.652Z', () => {
expect(dayjs().toISOString()).toBe(moment().toISOString())
})

it('Year 1 formatted with YYYY should pad with zeroes', () => {
const date = new Date(1, 0, 1)
date.setUTCFullYear(1) // Required because 0-99 are parsed as 19xx in JS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#year
expect(dayjs(date).format('YYYY')).toBe('0001')
})

it('Year 1 formatting matches moment format', () => {
const date = new Date(1, 0, 1)
date.setUTCFullYear(1)
expect(dayjs(date).format('YYYY')).toBe(moment(date).format('YYYY'))
})

0 comments on commit ea97f4c

Please sign in to comment.