Francesco Meli
Francesco Meli

Reputation: 2700

momentJs validity check is wrong

I have a special parser in my application that can parse relative and absolute times.

The parser breaks when moment recognize a relative time type as a valid absolute time.

How come:

let instance = moment('now-1d', 'YYYYMMDD')
instance.isValid()

returns true with date Mon Jan 01 0001 00:00:00 GMT+0049?

Upvotes: 0

Views: 38

Answers (1)

Durga
Durga

Reputation: 15604

Use strict parsing

let instance = moment('now-1d', 'YYYYMMDD',true)

console.log(instance.isValid())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>

Upvotes: 3

Related Questions