matthewmueller / date

Date() for humans
http://matthewmueller.github.io/date/
1.48k stars 88 forks source link

Why are you returning a default date when the supplied input is invalid? #101

Open arizonatribe opened 3 years ago

arizonatribe commented 3 years ago

This is such a basic piece of functionality and it makes this package unusable in cases where input must be validated. So what is the thinking here and why has date.js been created in a way that faulty input like this:

date("blah")

actually returns a valid date?

In use cases where an end user is trying to run a search for a time/date range it isn't desired to have every failed parsing default to now/today.

So why is it built this way and why is there no configuration option to turn that off? If a bad date string is provided I wouldn't personally want any value returned.

It's very easy for consumers of date.js to do this if they always want a date value:

function parseDate(val) {
  return date(val) || date("now")
}

But there isn't a way for us to ensure that invalid date values are rejected.

Can this be fixed?

madewithkode commented 1 year ago

This is such a basic piece of functionality and it makes this package unusable in cases where input must be validated. So what is the thinking here and why has date.js been created in a way that faulty input like this:

date("blah")

actually returns a valid date?

In use cases where an end user is trying to run a search for a time/date range it isn't desired to have every failed parsing default to now/today.

So why is it built this way and why is there no configuration option to turn that off? If a bad date string is provided I wouldn't personally want any value returned.

It's very easy for consumers of date.js to do this if they always want a date value:

function parseDate(val) {
  return date(val) || date("now")
}

But there isn't a way for us to ensure that invalid date values are rejected.

Can this be fixed?

Currently working with date.js and this has been a really significant issue and I can't seem to find a work around for it yet. Really curious to understand what the constraints or the thinking behind not having a utility to ascertain invalid inputs were. Maybe it's another case of twitter adding an edit feature :)