iamkun / iamkun/dayjs

Parsing hours using single digit without separator gives invalid results

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

Trying to parse single digit hours doesn't work correctly when there is no separator character:

`dayjs("20240726 931", 'YYYYMMDD Hmm', true).isValid() // false, expected true`
`dayjs("931", 'Hmm', true).isValid() // false, expected true`
`dayjs("20240726 931", 'YYYYMMDD Hmm', true).hour() // 21, expected 9`

If there is a separator between H and mm then result is as expected:

`dayjs("20240726 9 31", 'YYYYMMDD H mm', true).isValid() // true, expected true`
`dayjs("9 31", 'H mm', true).isValid() // true, expected true`
`dayjs("9 31", 'H mm', true).hour() // 9, expected 9`

**Information**
- Day.js Version: v1.11.12
- OS: Windows
- Browser: Edge 127.0.2651.98
- Time zone: UTC +3 EEST (Eastern European Summer Time)

Contributor guide

Open the contributing guide

Research direction

Reproduce the strict parsing examples for `H` and `Hmm`, comparing inputs with and without a separator, and inspect the date-format parsing entry points they exercise. Add regression coverage for single-digit hours without a separator; done means the examples are valid and return hour 9 as expected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.