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 .. in moment.add() function #3703

Closed
a-eid opened this issue Jan 6, 2017 · 1 comment
Closed

Bug .. in moment.add() function #3703

a-eid opened this issue Jan 6, 2017 · 1 comment

Comments

@a-eid
Copy link

a-eid commented Jan 6, 2017

this image explains it

http://i.imgur.com/pBWzdBZ.png

@butterflyhug
Copy link
Contributor

This is not a bug. Each time you call .add(), you're updating the value of now to be the result of that addition. E.g. when i=2, you're adding 2 days to the previous result, which was Sunday. That's why the new result is Tuesday.

If you don't want to change the value of now, then you should create a copy with .clone() before changing the value with .add(...). In your example you'd want to do this on every loop iteration: now.clone().add(i, "days")

We're planning to change this behavior in 3.0 later this year. The tracking issue for that change is #1754.

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

2 participants