dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Parse error when time is before 1000-01-01

Open PengJiyuan opened this issue 3 years ago • 2 comments
trafficstars

Describe the bug

dayjs('0001-01-01').format('YYYY-MM-DD') // 1901-01-01
dayjs('1-01-01').format('YYYY-MM-DD') // 2001-01-01

So who knows how to parse 0001-01-01 or -0001-01-01.

Expected behavior

dayjs('0001-01-01').format('YYYY-MM-DD') // 0001-01-01

Information

  • Day.js Version:v1.10.7
  • OS: Mac
  • Browser: Chrome
  • Time zone: GMT+08:00

PengJiyuan avatar Sep 02 '22 08:09 PengJiyuan

Confirming this bug

  • Node v16.17.0
  • DayJS : 1.11.5

You can fix by specifying the time :

> dayjs('0001').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t00').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t00:00').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t00:00:00').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t00:00:00z').format('YYYY-MM-DD')
'1-01-01'
> dayjs('0001-01-01z').format('YYYY-MM-DD')
'2001-01-01'

cl-parsons avatar Sep 03 '22 12:09 cl-parsons

Same error here (v1.11.5, Chrome). Trying to display year 0001 and always getting 1901 instead

It should be able to parse it accordingly (as momentJS does) dayjs('0001-01-01').format('YYYY-MM-DD') -> 0001-01-01

adrigardi90 avatar Sep 08 '22 14:09 adrigardi90