-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Incorrect .add() result with timezone plugin #2195
Comments
I suppose this is a GMT topic is in issue #2037 and solved in pull request #2118. Testdescribe('issue 2195 - add in UTC timezone', () => {
it('Thu Dec 01 2022 00:00:00 GMT+0800, with "+ 1 month"', () => {
dayjs.extend(utc)
dayjs.extend(timezone)
expect(dayjs(1669852800000).tz(GMT).add(1, 'month').format()).toBe('2023-01-01T00:00:00Z')
expect(dayjs(1669852800000).tz(GMT).add(1, 'month').isSame(moment(1669852800000).tz(GMT).add(1, 'M'))).toBe(true)
})
})
// pass result : 2023-01-01T00:00:00.000Z |
Sorry that I can not get the same result as you did 😭. I cloned the repo and installed moment-timezone as Moment.js Doc said and then run this case, but the output of testing is failed. // timezone.test.js
import MockDate from 'mockdate'
// import moment from 'moment'
import dayjs from '../src'
import timezone from '../src/plugin/timezone'
import utc from '../src/plugin/utc'
import moment from 'moment-timezone';
// ...
it('test issue #2195', () => {
console.log(dayjs(1669852800000).tz('GMT').add(1, 'month'))
expect(dayjs(1669852800000).tz('GMT').add(1, 'month').isSame(moment(1669852800000).tz('GMT').add(1, 'M'))).toBe(true);
}) And the result is
Moment is the correct result. I have debugged the running progress of |
You cloned this repo https://github.com/BePo65/dayjs/tree/fix/issue2037 ? |
I cloned the repo itself dayjs and run the test cases in branch 'dev', here is my result: And I found that when my machine timezone setting was UTC+8, the cases failed, but when I changed to UTC+0, cases passsed. |
Okay, have you tried with this repo dayjs ? it fixes some timezone plugin errors |
Ok, I used the repo you said above and changed the branch to 'fix/issue2037' and the test case passed successfully.🎉 Thanks for your patience, and may I ask when will this branch be merged into main? |
no worries, with pleasure. unfortunately I don't have this information. |
Hi 👋 |
Hi, |
Hi 👋🏼 |
Describe the bug
Hi Team, there is a confusing problem I'm facing with:
There is a timestamp, and I transform it into a dayjs object with the timezone plugin. But when I use
.add(1, 'month')
, the result is wrong, which seems to be added too much😫.And the result is:
Here is my codesandbox link: https://codesandbox.io/s/dank-lake-kc5w1i?file=/src/index.js
Expected behavior
It should be '2022-01-01T00:00:00.000Z'
Information
The text was updated successfully, but these errors were encountered: