iamkun / dayjs

⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
https://day.js.org
MIT License
46.24k stars 2.26k forks source link

Big Bug!!!!!! Date acquisition exception and parsing time exception #2662

Open smithyj opened 1 month ago

smithyj commented 1 month ago

Case:

dayjs(`0001-12-01 00:00:00`).get("year") // 1901
moment(`0001-12-01 00:00:00`).get("year") // 1,expected

Case:

dayjs(`0001-12-00 00:00:00`).get("year") // 1901
moment(`0001-12-00 00:00:00`).get("year") // NaN,expected

Case:

dayjs("1100-12-00 00:00:00").isValid() // true
moment("1100-12-00 00:00:00").isValid() // false,expected

Case:

dayjs("1100-00-00 00:00:00").isValid() // true
dayjs("1100-00-01 00:00:00").isValid() // true
moment("1100-00-00 00:00:00").isValid() // false,expected
moment("1100-00-01 00:00:00").isValid() // false,expected

Case:

dayjs("0000-00-00 00:00:00").isValid() // true
moment("0000-00-00 00:00:00").isValid() // false,expected

There are more cases with issues.

mike-kaonashi commented 1 month ago

Your cases of .isValid() API stuffs somehow not a bug, its a feature otherwise. You can check the code, they are using the regex to check your input as below /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/ I think .isValid() still cause some unexpected bugs cuz I faced some

smithyj commented 1 month ago

@mike-kaonashi But .get() cases is return error