dayjs doesn't say that the invalid date is invalid (eg 2025-36-36T14:19:39) (ISO format)
Describe the bug When initializing dayjs with the invalid date (day 40 or month 13), it doesn't say that the date is invalid.
example:
dayjs('2025-13-36T14:19:39')
// Thu, 05 Feb 2026 12:19:39 GMT
Expected behavior
date.isValid should return false.
Information
- Day.js Version [e.g. v1.11.13]
- Framework: Nodejs v22.15.0
- Time zone: GMT+02:00 DST
I am the author of this issue, I've done some migrations between accounts, so I am leaving this comment here so that you'll be able to communicate with me and so that I can keep track of this issue.
By default, Day.js uses a lenient parsing mode and will try to parse a datetime input as much as possible, even if the values are not strictly valid.
If you need strict parsing, you may have to:
- Tell Day.js the exact format to parse.
- Enable the strict flag by passing
trueas the third argument.
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)
const strictDate = dayjs('2025-13-36T14:19:39', 'YYYY-MM-DDTHH:mm:ss', true)
console.log(strictDate.isValid()) // false
@iamkun Don't you think that there should be a separate flag for it in addition? Like in the pr I've provided? We have a use case where users are using free format, but not allowed to use lenient dates. Right now I've added a custom plugin that would do this, but not sure if this should be natively supported or not.
What do you think?