`.valueOf` does not work properly with `utc` and `timezone` plugins
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When NodeJS is configured The combination of `utc` and `timezone` plugins does not handle `.valueOf` function properly
Code to reproduce
```javascript
process.env.TZ = 'Europe/Amsterdam';
await import('dayjs').then(m => {dayjs = m.default;});
await import('dayjs/plugin/arraySupport.js').then(m => {arraySupport = m.default;});
await import('dayjs/plugin/timezone.js').then(m => {timezone = m.default;});
await import('dayjs/plugin/utc.js').then(m => {utc = m.default;});
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(arraySupport);
var withoutTimezone = dayjs.utc([2021, 1, 26, 19, 13, 55, 751]);
console.log(withoutTimezone.format()); // 2021-02-26T19:13:55Z
var tenHoursBefore = withoutTimezone.clone().utcOffset(10, true);
console.log(tenHoursBefore.format()); // 2021-02-26T19:13:55+10:00
var diffInHours = (withoutTimezone.valueOf() - tenHoursBefore.valueOf()) / (1000 * 60 * 60);
console.log(diffInHours); // Error: 9 hours, Expected: 10 hours
```
**Expected behavior**
When `utc.utcOffset` returns dayJs object without local host machine's timezone.
**Information**
- Day.js Version [e.g. v1.0.0] : v1.11.10
- OS: [e.g. iOS] : Mac OS X
- Browser [e.g. chrome 62] : Not applicable
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)] : GMT+09:00 (Asia/Tokyo)
Contributor guide
Research direction
Start by running the supplied Node.js reproduction with the utc, timezone, and arraySupport plugin entry points. Trace the valueOf and utcOffset behavior, then add or update a focused regression test showing that the offset difference is 10 hours without depending on the host timezone.
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
- 48/100