iamkun / iamkun/dayjs

"IsSame" After TZ Conversion Yields False

Open
#1,208 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
This code snippet illustrates the bug -

```
const date = dayjs('2020-11-23T12:00:00-06:00', 'YYYY-MM-DDTHH:mm:ssZ', true);
const equivalentDate = dayjs('2020-11-23', 'YYYY-MM-DD', true);
const goodResult = date.isSame(equivalentDate, 'date');

const desiredTz = 'America/Phoenix';
const transformedTzDate = dayjs.tz(date, desiredTz);

const badResult = transformedTzDate.isSame(equivalentDate, 'date');
```

In this example, `goodResult` is true, while `badResult` is false. I would expect both of them to be true. The timezone transformation in this case does not alter the date, going from `-06:00` to `−07:00` (America/Phoenix) is only 1 hour behind. So `date = November 23, 2020 12:00` and `transformedTzDate = November 23, 2020 11:00`. You can see that comparing the dates should still yield true for 'isSame'.

**Expected behavior**
In the above example, I would have expected `badResult` to equal `true`. A date after changing timezone should still equal the same date in another timezone.

**Information**
- Day.js Version [e.g. v1.0.0]
- OS: macOS Catalina
- Browser Chrome Version 86.0.4240.80
- Time zone: I ran this test while my machine was set to `−05:00`.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied `isSame` and `dayjs.tz` example, then trace the timezone conversion and date-unit comparison paths used by those calls. Confirm that the converted date and the equivalent date compare as expected for the `date` unit, and add or update coverage for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.