iamkun / iamkun/dayjs

isSame produces incorrect results when DST ended in local zone but haven't ended yet in the desired timezone

Open
#1,399 0 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**

I'm having an issue when two exactly the same dates are sometimes not the same when compared using the `isSame` function.

Those dates are in different timezone (`America/New_York`) than the local timezone (`Europe/Bratislava`).

What's weird is that the the `isSame` function produces correct results on dates when both timezones are in standard time, but it produces incorrect results when Europe is already on summer time, but US is still on standard time.

**Minimal reproducible example**

In Node.js 14:

```js
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')

dayjs.extend(utc)
dayjs.extend(timezone)

const test = str => {
let tz = 'America/New_York'
let day1 = dayjs(str).tz(tz)
let day2 = dayjs(str).tz(tz)
return day1.isSame(day2)
}

console.log(test('2021-03-28T00:00:00Z')) // prints "true"
console.log(test('2021-03-29T00:00:00Z')) // prints "false"
```

**Expected behavior**

```js
console.log(test('2021-03-29T00:00:00Z')) // prints "true"
```

**Information**
- Day.js Version: 1.10.4
- OS: Ubuntu 20.04
- Browser: Node.js v14.16.0 REPL
- Time zone: UTC+01:00 (Central European)

Contributor guide

Open the contributing guide

Research direction

Start by locating the isSame implementation and the utc/timezone plugin entry points, then run the Node.js reproduction from the issue. Compare the two dates around the Europe/Bratislava and America/New_York DST transition; done means the 2021-03-29 example returns true while the existing behavior remains correct.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.