Comparison functions (e.g. isAfter()) not working with timezone dates
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
Date comparison functions like `isAfter()` do not work with `dayjs.tz` dates.
**Example**
```javascript
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.tz.setDefault('Europe/Berlin')
console.log('working as expected:')
let before = dayjs('2021-01-03T20:00:00+01:00')
let after = dayjs('2021-01-03T20:30:00+01:00') //30 minutes later
console.log('before:', before.format()) // => 2021-01-03T20:00:00+01:00
console.log('after:', after.format()) // => 2021-01-03T20:30:00+01:00
console.log('after.isAfter(before) ==>', after.isAfter(before)) // => true ✅
console.log('before.isAfter(after) ==>', before.isAfter(after)) // => false ✅
console.log('\n')
console.log('NOT working as expected:')
before = dayjs.tz('01.03.2021 21:00:00', 'DD.MM.YYYY HH:mm', 'Europe/Berlin')
after = dayjs.tz('01.03.2021 21:30:00', 'DD.MM.YYYY HH:mm', 'Europe/Berlin') //30 minutes later
console.log('before:', before.format()) // => 2021-01-03T20:00:00+01:00
console.log('after:', after.format()) // => 2021-01-03T20:30:00+01:00
console.log('after.isAfter(before) ==>', after.isAfter(before)) // => false ❌
console.log('before.isAfter(after) ==>', before.isAfter(after)) // => false ✅
```
**Information**
- Day.js Version: v1.8.34
- OS: MacOS 11.2.3
- Node.js
- Time zone: CET
Contributor guide
Research direction
Start by running the supplied Node.js reproduction with the utc and timezone plugins, then inspect the dayjs.tz entry point and comparison functions such as isAfter(). Done means timezone-created dates produce the expected true/false comparison results shown in the 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