iamkun / iamkun/dayjs

Prevent parsing to local timezone

Open
#1,430 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

Is it possible with dayjs to _not_ parse a date string to the local timezone?

I'm running dayjs on a nodejs server and the server could have to deal with dates in all kinds of timezones. Basically I might get a string get sent to it that looks like `'2021-03-24T10:00:00-04:00'` and when I do anything with that, I want it to retain it's local values and not whatever that would translate to based on the local server.

```
const dateString = '2021-03-24T10:00:00-04:00'
const date = dayjs(dateString)

const time = date.format('h:mm A')
```

If I do the above, what I'd want is for time to be `10:00 AM`, and not `2:00 PM` as I'm getting now (my local server is running in GMT).

Is this possible?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the behavior with the dayjs(dateString) and date.format('h:mm A') calls shown in the issue. Investigate how parsing an offset date string and formatting it interact, then define and verify behavior that preserves the input's local clock values without depending on the server timezone.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.