Skip to content

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

@arizonatribe

Description

@arizonatribe

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions