iamkun / iamkun/dayjs

Incorrect parsing of fractional seconds in ISO-8601 when no timezone is specified

Open
#1,923 4 comments 1 reaction 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**
DayJS thinks that the time `'00:00:00.5'` is five milliseconds after midnight, but it should be 500 milliseconds after midnight.

Reproduction:

```ts
const dayjs = require('dayjs');
const dateWithoutSpecifiedTimezone = dayjs('2000-01-01T00:00:00.5');
const dateInUTC = dayjs('2000-01-01T00:00:00.5Z');

dateInUTC.toISOString(); // '2000-01-01T00:00:00.500Z' - Correct
dateWithoutSpecifiedTimezone.toISOString(); // '2000-01-01T00:00:00.005Z' - Incorrect - should be '2000-01-01T00:00:00.500Z'
```

**Expected behavior**
It should interpret the number of seconds `ss.SSS` as a decimal fraction, no matter how many decimal places are given, regardless of whether there is a timezone specified

**Information**
- Day.js Version: 1.11.2
- OS: macOS 12
- Browser: Bug reproduced in Safari and Node.js
- Time zone: BST (UTC+1)

Contributor guide

Open the contributing guide

Research direction

Run the provided Node.js reproduction and compare the outputs with and without the timezone suffix. Trace Day.js's ISO-8601 parsing entry point to the fractional-seconds handling; done means both inputs serialize with .500Z as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
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.