Different TZ offset on different machines for startOf('day') and ZZ format
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I am using NodeJS. `startOf('day')` uses GMT-5 on my local machine (Windows, New York TZ) and GMT-4 on a GCP instance (Linux, UTC). Similarly `ZZ` format option shows GMT-5 locally (that is actually wrong) and GMT-4 on a GCP instance.
Code to reproduce the issue:
```js
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const timezone = require('dayjs/plugin/timezone');
dayjs.extend(utc);
dayjs.extend(timezone);
const timeZone = 'America/New_York';
const time = new Date('2020-10-25T15:14:00-04:00');
const startOfDay = dayjs.tz(time, timeZone).startOf('day').toDate();
const midnight = dayjs.tz(time, timeZone).hour(0).minute(0).second(0).millisecond(0).toDate();
const rfc822 = dayjs.tz(time, timeZone).format('ddd, DD MMM YYYY HH:mm:ss ZZ');
const fromRfc822 = new Date(rfc822);
console.log(time);
console.log(startOfDay);
console.log(midnight);
console.log(rfc822);
console.log(fromRfc822);
```
Output from local system:
```
2020-10-25T19:14:00.000Z
2020-10-25T05:00:00.000Z
2020-10-25T04:00:00.000Z
Sun, 25 Oct 2020 15:14:00 -0500
2020-10-25T20:14:00.000Z
```
Output from GCP instance
```
2020-10-25T19:14:00.000Z
2020-10-25T04:00:00.000Z
2020-10-25T04:00:00.000Z
Sun, 25 Oct 2020 15:14:00 -0400
2020-10-25T19:14:00.000Z
```
Notice that the first line shows the original `Date` object and the last line shows an object made by re-parsing the output of `format`. They are not the same depending on the TZ of the system they are on.
**Expected behavior**
`startOf('day')` should return midnight or docs should warn that day start and midnight are different concepts
`startOf('day')` should return the same output regardless of the TZ of the system that it is running on
`ZZ` format should use correct TZ offset
`ZZ` format should use the same offset regardless of the system that it is running on
**Information**
- Day.js Version 1.10.4
- OS: Local Windows 10, GCP Instance Debian 9
- Browser N/A, NodeJS
- Time zone: America/New_York on 2/10/2021 (UTC-5, Eastern Standard Time)
Contributor guide
Research direction
Start with the utc and timezone plugin entry points and reproduce the supplied NodeJS case on Windows and Debian/GCP environments. Compare startOf('day'), the explicit midnight setters, and ZZ parsing against the stated expected behavior; done means the result is consistent across system time zones or the distinction is clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100