Skip to content

Commit

Permalink
test: add day string tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlogozzo committed Jan 12, 2025
1 parent e4ca7c0 commit c21d738
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,35 @@ it('parse w, ww', () => {
const format2 = 'YYYY-[w]ww'
expect(dayjs(input2, format2).format(format1)).toBe(input2)
})

describe('parse day strings', () => {
it('parse day from string', () => {
const input1 = 'Friday, 10 Jan 2025'
const format1 = 'dddd, DD MMM YYYY'
expect(dayjs(input1, format1).format(format1)).toBe(input1)
expect(dayjs(input1, format1).valueOf()).toBe(moment(input1, format1).valueOf())
const input2 = '10 Jan 2025'
const format2 = 'DD MMM YYYY'
expect(dayjs(input2, format2).format('dddd')).toBe(moment(input1, format1).format('dddd'))
})

it('parse day from short string', () => {
const input1 = 'Fri, 10 Jan 2025'
const format1 = 'ddd, DD MMM YYYY'
expect(dayjs(input1, format1).format(format1)).toBe(input1)
expect(dayjs(input1, format1).valueOf()).toBe(moment(input1, format1).valueOf())
const input2 = '10 Jan 2025'
const format2 = 'DD MMM YYYY'
expect(dayjs(input2, format2).format('ddd')).toBe(moment(input1, format1).format('ddd'))
})

it('parse day from min string', () => {
const input1 = 'Fr, 10 Jan 2025'
const format1 = 'dd, DD MMM YYYY'
expect(dayjs(input1, format1).format(format1)).toBe(input1)
expect(dayjs(input1, format1).valueOf()).toBe(moment(input1, format1).valueOf())
const input2 = '10 Jan 2025'
const format2 = 'DD MMM YYYY'
expect(dayjs(input2, format2).format('dd')).toBe(moment(input1, format1).format('dd'))
})
})

0 comments on commit c21d738

Please sign in to comment.