iamkun / iamkun/dayjs

Returning date as an object in system timezone

Open
#2,701 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**
My system time is PST and trying to convert to CST. Here's what we have:

```
dayjs.extend(relativeTime)
dayjs.extend(advancedFormat)
dayjs.extend(utc)
dayjs.extend(timezone)

dayjs.tz.setDefault('America/Chicago')

const timezonedDayjs = (...args: any[]) => dayjs(...args).tz()

export default timezonedDayjs
```

`timezonedDayjs().format()` will return the correct date, time and timezone (good) but in a string (bad)
`timezonedDayjs().toDate()` will return the correct date and time but incorrect timezone (bad) but in an object (good)

Is there any way to have `timezonedDayjs` return the correct timezone (CST) in the correct format (object)?

**Expected behavior**
A clear and concise description of what you expected to happen.

**Information**
- Day.js Version v 1.11.10
- OS: Mac OS 14.5
- Browser Chrome 126.X
- Time zone: GMT-0500 Central Standard Time

Contributor guide

Open the contributing guide

Research direction

The issue names no source file or test. Begin by reproducing the shown utc and timezone plugin setup with dayjs.tz.setDefault('America/Chicago'), then inspect how format() and toDate() represent the same value. Done would require a documented or tested resolution for the requested timezone-aware object behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.