iamkun / iamkun/dayjs

Parse with a default offset (if string does not specify)

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

I'm working with a service that provides two types of date strings:

- local times, which need to be parsed in the context of the local offset / tz
- iso times, which specify their offset (in my case, always UTC)

I've resorted to this hacky parse helper:

```js
function parseTime(s, tz) {
if (s.endsWith('Z')) return dayjs(s).tz(tz)
return dayjs.tz(s, tz)
```

This is needed because dayjs.tz overrides the offset, even for iso strings which specify offset.

It feels like a bug in dayjs.tz, and in fact had different behavior in 1.9.7...

Dayjs 1.10.7

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported behavior with dayjs.tz on offset-less and UTC-suffixed strings using Day.js 1.10.7, then compare it with the behavior in 1.9.7. Trace how dayjs.tz handles an offset already present in the input; done means specified offsets are preserved while offset-less strings use the supplied timezone.

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.