iamkun / iamkun/dayjs

Using isBetween from Invalid Date return true when using '[]' as a 4th parameter

Open
#2,097 0 comments 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

**Describe the bug**
Found this bug when accidentally put null to constructor.
```
dayjs(null).isBetween(dayjs('2022-01-28'), dayjs('2022-02-28'), 'day', '[]'); // returns true;
dayjs('random string').isBetween(dayjs('2022-01-28'), dayjs('2022-02-28'), 'day', '[]'); // returns true;
dayjs('random string').isBetween(dayjs('2022-01-28'), dayjs('2022-02-28'), 'day', '[)'); // returns false;
dayjs('random string').isBetween(dayjs('2022-01-28'), dayjs('2022-02-28'), 'day', '(]'); // returns false;
dayjs('random string').isBetween(dayjs('2022-01-28'), dayjs('2022-02-28'), 'day', '()'); // returns false;

dayjs('2022-01-27').isBetween(dayjs('2022-01-28'), dayjs('2022-02-28'), 'day', '[]'); // returns false;
```

**Expected behavior**
Invalid Date should always return false when using isBetween

**Information**
- Day.js Version [e.g. v1.0.0]: latest (tested on dayjs homepage)
- OS: [e.g. iOS] macOS
- Browser [e.g. chrome 62] Chrome 106
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)] UTC+9

Contributor guide

Open the contributing guide

Research direction

Reproduce the provided isBetween examples with invalid dates and each inclusivity parameter. Start at the isBetween entry point and trace how invalid dates and the '[]' bounds are evaluated. Done means invalid dates consistently return false, with tests covering the reported cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.