-
-
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 result: 3:00:01 minus 2 second = 1:59:59 depend on env.TZ #2152
Comments
related issue: #2184 |
Hi 👋 On dev branch, on Day.js v1.11.7 and on #2118 : describe('issue 2152 - result not match, depends on env.TZ', () => {
it('Sat Mar 12 2022 09:00:01 NY, LA, TOKYO tz, to NY, LA, TOKYO tz', () => {
const date = '2022-03-13 03:00:01'
const LA = 'America/Los_Angeles'
const mDate = tz => moment(date).tz(tz)
const dDate = tz => dayjs(date).tz(tz)
expect(dayjs(dDate(NY)).tz(LA).subtract(2, 's').format()).toBe(moment(mDate(NY)).tz(LA).subtract(2, 's').format())
expect(dayjs(dDate(NY)).tz(TOKYO).subtract(2, 's').format()).toBe(moment(mDate(NY)).tz(TOKYO).subtract(2, 's').format())
expect(dayjs(dDate(LA)).tz(NY).subtract(2, 's').format()).toBe(moment(mDate(LA)).tz(NY).subtract(2, 's').format())
expect(dayjs(dDate(LA)).tz(TOKYO).subtract(2, 's').format()).toBe(moment(mDate(LA)).tz(TOKYO).subtract(2, 's').format())
expect(dayjs(dDate(TOKYO)).tz(LA).subtract(2, 's').format()).toBe(moment(mDate(TOKYO)).tz(LA).subtract(2, 's').format())
expect(dayjs(dDate(TOKYO)).tz(NY).subtract(2, 's').format()).toBe(moment(mDate(TOKYO)).tz(NY).subtract(2, 's').format())
})
}) // pass Hoping that this will solve your problem 😉 |
@KronosDev-Pro $ TZ=Asia/Tokyo jest test/issues/issue2152.test.js
PASS test/issues/issue2152.test.js
issue 2152 - result not match, depends on env.TZ
✓ Sat Mar 12 2022 09:00:01 NY, LA, TOKYO tz, to NY, LA, TOKYO tz (16ms)
$ TZ=America/New_York jest test/issues/issue2152.test.js
FAIL test/issues/issue2152.test.js
issue 2152 - result not match, depends on env.TZ
✕ Sat Mar 12 2022 09:00:01 NY, LA, TOKYO tz, to NY, LA, TOKYO tz (17ms)
● issue 2152 - result not match, depends on env.TZ › Sat Mar 12 2022 09:00:01 NY, LA, TOKYO tz, to NY, LA, TOKYO tz
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"2022-03-12T22:59:59-08:00"
Received:
"2022-03-12T22:59:59-07:00" The problem here is that the day.js's result is not constant but depends on import MockDate from 'mockdate'
import dayjs from '../../src'
import utc from '../../src/plugin/utc'
import timezone from '../../src/plugin/timezone'
dayjs.extend(utc)
dayjs.extend(timezone)
const moment = require("moment")
require("moment-timezone")
beforeEach(() => {
MockDate.set(new Date())
})
afterEach(() => {
MockDate.reset()
})
describe('issue 2152 - result not match, depends on env.TZ', () => {
it('Sat Mar 12 2022 09:00:01 NY, LA, TOKYO tz, to NY, LA, TOKYO tz', () => {
const date = '2022-03-13 03:00:01'
const LA = 'America/Los_Angeles'
const NY = 'America/New_York'
const TOKYO = 'Asia/Tokyo'
const mDate = tz => moment(date).tz(tz)
const dDate = tz => dayjs(date).tz(tz)
expect(dayjs(dDate(NY)).tz(LA).subtract(2, 's').format()).toBe(moment(mDate(NY)).tz(LA).subtract(2, 's').format())
expect(dayjs(dDate(NY)).tz(TOKYO).subtract(2, 's').format()).toBe(moment(mDate(NY)).tz(TOKYO).subtract(2, 's').format())
expect(dayjs(dDate(LA)).tz(NY).subtract(2, 's').format()).toBe(moment(mDate(LA)).tz(NY).subtract(2, 's').format())
expect(dayjs(dDate(LA)).tz(TOKYO).subtract(2, 's').format()).toBe(moment(mDate(LA)).tz(TOKYO).subtract(2, 's').format())
expect(dayjs(dDate(TOKYO)).tz(LA).subtract(2, 's').format()).toBe(moment(mDate(TOKYO)).tz(LA).subtract(2, 's').format())
expect(dayjs(dDate(TOKYO)).tz(NY).subtract(2, 's').format()).toBe(moment(mDate(TOKYO)).tz(NY).subtract(2, 's').format())
})
}) // pass |
It's not still fixed at commit 231ff0f fix/issue2037 branch as well. |
Describe the bug
subtract()
method may return an incorrect result withdayjs/plugin/timezone
depend on the place where you runs the script.If you run it at Tokyo, it returns a correct result.
If you run the same code at New York, however, it returns an incorrect value.
Note that we don't have the DST daylight saving time system in Tokyo.
And in the U.S., March 13 was the day to switch from STD to DST at 2022.
Expected behavior
subtract()
method should return the incorrect result wherever you run the script likemoment-timezone
have done.Information
America/New_York
The text was updated successfully, but these errors were encountered: