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

add or subtract by 'date' is not working #681

Open
HDNRAY opened this issue Sep 25, 2019 · 9 comments
Open

add or subtract by 'date' is not working #681

HDNRAY opened this issue Sep 25, 2019 · 9 comments

Comments

@HDNRAY
Copy link

HDNRAY commented Sep 25, 2019

Describe the bug
add or subtract by 'date' is not working. by 'day' works, but then we can not use same type on all progress.

Expected behavior
add or subtract by 'date' works.

Information

  • Day.js 1.8.15
@iamkun
Copy link
Owner

iamkun commented Sep 25, 2019

What's this add date stand for?

@Silver47Gin
Copy link

What's this add date stand for?

In doc, date stands for day in month and day stands for day in week. Allow for using set(x,'date') but not add(x,'date') can be confusing. Maybe make add(n,'date') and add(n,'day') have the same effect will make sense.

@HDNRAY
Copy link
Author

HDNRAY commented Nov 22, 2019

What's this add date stand for?

In doc, date stands for day in month and day stands for day in week. Allow for using set(x,'date') but not add(x,'date') can be confusing. Maybe make add(n,'date') and add(n,'day') have the same effect will make sense.

Or make add(n,'day') for day in week and add(n,'date) for day in month. Each 'type' keeps the same meaning for all APIs.

@iamkun
Copy link
Owner

iamkun commented Nov 22, 2019

I'll pending this issue at present.
I do think adding add('date') will surely cause another confusion.

@franksun1988
Copy link

I found same problem.

@bogdan-nourescu
Copy link

I just ran into this problem too. I usually manipulate only date, without time, and i have to use date for set and day for add/subtract.
If add date will not be fixed/added as a feature, i would like it to be removed from the add DOCS:
https://github.com/dayjs/dayjs-website/blob/master/docs/manipulate/add.md

I read it in the docs and it seem that it will work, but, no error, no invalid date, no nothing, it just silently ignored the add call, that made me more confused and on issue hunt.

@iamkun
Copy link
Owner

iamkun commented May 27, 2020

@bogdan-nourescu thanks, removed. That's an error.

@innovaweb-dev
Copy link

I have same problem.

tmp = new dayjs();
tmp.add(7,'d'); // don't change the date.

// but inline, that works
tmp = new dayjs().add(7, 'd') //added 7 days.

@HDNRAY
Copy link
Author

HDNRAY commented Feb 22, 2021

I have same problem.

tmp = new dayjs();

tmp.add(7,'d'); // don't change the date.



// but inline, that works

tmp = new dayjs().add(7, 'd') //added 7 days.

not same. Your problem is due to dayjs is immutable.

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

6 participants