iamkun / iamkun/dayjs

Timezone plugin with default timezone not working as expected

Open
#1,249 2 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

**Description**

Hello everybody, it seems that `dayjs().tz().toDate()` does not take into account the timezone defined by default.

**Expected behavior**

```javascript
console.log(dayjs().toDate());
//Fri Dec 04 2020 15:45:37 GMT+0100 (heure normale d’Europe centrale)
```
```javascript
dayjs.tz.setDefault('Asia/Shanghai')
```

```javascript
console.log(dayjs().tz().toDate());
//Fri Dec 04 2020 15:45:37 GMT+0100 (heure normale d’Europe centrale)
```
I'd expect to have a date with the right timezone when doing `dayjs().tz().toDate()`

**Information**

- Day.js: Version 1.9.6
- OS: Linux (Ubuntu 20.04)
- Timezone: CET / 'Europe/Paris' (GMT+1)

Contributor guide

Open the contributing guide

Research direction

Start by reading the timezone plugin implementation and tracing the dayjs().tz().toDate() entry points, including how dayjs.tz.setDefault('Asia/Shanghai') is applied. Compare the observed and expected behavior, then add or update coverage for the default-timezone case so the intended result is explicit.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
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.