Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: fromNow() gives the wrong result for invalid number #2079

Closed
alexewerlof opened this issue Dec 2, 2014 · 3 comments
Closed

Bug: fromNow() gives the wrong result for invalid number #2079

alexewerlof opened this issue Dec 2, 2014 · 3 comments

Comments

@alexewerlof
Copy link

What is the bug?

> var j = moment(NaN)
undefined
> j.fromNow()
"a few seconds ago"
> j.calendar()
"Invalid date"

Why is it a bug?

  1. Inconsistency (calendar() correctly detects that this date is invalid but fromNow() blindly spit out results
  2. Probability. In our case we parse an angular attribute like this: moment(Number(attrs.epoch)) and instead of saying "Invalid date" it says "a few seconds ago".

version : 2.8.3

@mattgrande
Copy link
Contributor

Counter-point: Calling isValid() correctly returns false, so that should be all that matters. You should expect to see incorrect data when using an invalid date, and it should be up to the developer to handle that.

I agree it "feels" wrong, though... Perhaps the fromNow() method could return "Invalid date" if isValid() is false?

@alexewerlof
Copy link
Author

Perhaps the fromNow() method could return "Invalid date" if isValid() is false?

That would be great.

@donaldpcook
Copy link

Added a pull request if this is the route that we want to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants