iamkun / iamkun/dayjs

Wrong behaviour of isBefore when using timezones

Open
#2,182 2 comments 1 reaction 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**
Comparing two dayjs instances in a specific timezone wich are 1 minute apart a before each other.

```javascript
var d1 = dayjs().tz('Europe/Berlin').year(2023).month(3).date(10).hour(0).minute(0).second(0).millisecond(0)
var d2 = d1.subtract(1, 'minute')
d1.isBefore(d2)
> true
d2.isBefore(d1)
> true
```

This is not happening when you are not using a timezone:

```javascript
var d1 = dayjs().year(2023).month(3).date(10).hour(0).minute(0).second(0).millisecond(0)
var d2 = d1.subtract(1, 'minute')
d1.isBefore(d2)
> false
d2.isBefore(d1)
> true
```

**Expected behavior**
The later instance should return false when using `isBefore`.

**Information**
- Day.js Version v1.11.5
- OS: macOS
- Browser Chrome 108.0.5359.124
- Time zone: GMT+0200

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.