iamkun / iamkun/dayjs

Differences between dayjs duration, and momentjs duration format

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

Description

**Note: This is a feature request, not a bug. The functionality works but does not work the same way as momenjs.**

**Describe the feature**
- Prefix zeroes are displayed in dayjs, but hidden in momentjs
- Momentjs rounds the laast displayed value, dayjs doesn't
- Not possible to display milliseconds w/o prefixing the numbers with zeroes

**Expected behavior**
```
moment.duration( 90 * 1000 ).format( 'H[h] m[m]' )
> 2m

dayjs.duration( 90 * 1000 ).format( 'H[h] m[m]' )
> 0h 1m
```

The 0h shown by dayjs is unnecessary. Especially when the duration can range between seconds till days, it's nice if only the relevant data is shown.
MomentJS rounds the last value in the format, thus 500ms would be shown as "1s" if milliseconds is not part of the format, while 499ms would show as 0s. And 90sec would be rounded to 2 minutes, if minutes is the precision.

```
moment.duration( 50 ).format( 'S[ms]' )
> 50ms

dayjs.duration( 50 ).format( 'S[ms]' )
> Sms [expected 50ms, but S does not exist]

dayjs.duration( 50 ).format( 'SSS[ms]' )
> 050ms
```

**Information**
- Day.js Version 1.10.7

Contributor guide

Open the contributing guide

Research direction

Start by locating the duration formatting entry point and reviewing how the examples in this issue are currently rendered. The work is done when relevant units can be omitted, the final displayed unit is rounded, and millisecond formatting does not require unwanted leading zeroes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.