iamkun / iamkun/dayjs

The behavior of tz's second parameter can be documented

Open
#1,487 0 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

**Describe the bug**
I'm not sure if this is the the expected behavior of the `tz` method with the second boolean parameter, but if it is, I feel it should be part of the document as it took me a while to figure out what the parameter does.

So basically you can use the conceptual UTC time in a different timezone when using `toDate` method with the second parameter set `true`. However the change is not applied to the `format` method. I'm ok with this, but I think we need some instructions on this one.

In the following example, I'm using `Asia/Tokyo` for the timezone (9 hours ahead of UTC time).

```
const sampleDate = new Date("2021-05-01T00:00:00+09:00");

console.log(dayjs(samepleDate).tz("Asia/Tokyo").format(`YYYY/M`)); // 2021/5
console.log(dayjs(samepleDate).tz("Asia/Tokyo", true).format(`YYYY/M`)); // 2021/4
console.log(dayjs(samepleDate).tz("Asia/Tokyo").toDate().getTime()); // 1588258800000 (2021/05/01 00:00 in JST)
console.log(dayjs(samepleDate).tz("Asia/Tokyo", true).toDate().getTime()); // 1588226400000 (2021/04/30 15:00 in JST)
```

**Expected behavior**
The behavior of tz's second parameter can be included in the official document.

https://day.js.org/docs/en/plugin/timezone

**Information**
- Day.js Version: v1.9.5
- OS: macOS
- Browser N/A
- Time zone: UTC+9 (Japan Standard Time)

Contributor guide

Open the contributing guide

Research direction

Start with the Day.js timezone plugin documentation at https://day.js.org/docs/en/plugin/timezone and review the `tz` method's second boolean parameter alongside the supplied examples. Done means the documentation clearly explains how that parameter affects `toDate` and how it differs from `format`.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.