iamkun / iamkun/dayjs

invalid date: wrong diff calculation for some units

Open
#2,793 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**
create a dayjs value from null and compare it with current dayjs value:
```
const currentDate = dayjs();
const expiresOn = dayjs(null);
```
Check difference for available units:
```
const diffDays = expiresOn.diff(currentDate, "days"); // NaN
const diffInWeeks = expiresOn.diff(currentDate, "week"); // NaN
const diffMonths = expiresOn.diff(currentDate, "month"); // 0
const diffInQuaters = expiresOn.diff(currentDate, "quarter"); // 0
const diffInYears = expiresOn.diff(currentDate, "year"); // 0
const diffInHours = expiresOn.diff(currentDate, "hour"); // NaN
const diffInMinutes = expiresOn.diff(currentDate, "minute"); // NaN
const diffInSeconds = expiresOn.diff(currentDate, "second"); // NaN

```
**Expected behavior**
return value should be NaN for all units

**Information**
- Day.js Version: 1.11,13
- OS: any
- Browser: any
- Time zone: any

Contributor guide

Open the contributing guide

Research direction

The issue provides a reproduction using dayjs(null), current dayjs(), and diff() for days, weeks, months, quarters, years, hours, minutes, and seconds. Start by running that example and tracing the diff behavior for each unit; it is done when every listed unit returns NaN for the invalid date.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.