iamkun / iamkun/dayjs

Duration validation tooling

Open
#2,223 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

Could it be possible to expose a method to validate a duration like the isValid method on the Dayjs date object?
```
console.log(dayjs.duration("PT1M").isValid()) // true
console.log(dayjs.duration("randomstring").isValid()) // false
// etc.
```
In the meantime, I will be using the inner regex to validate my durations, but having an embedded validation method would be a big plus.

edit: using isNaN(duration.milliseconds()) seems to be easier to use instead of regex.

Contributor guide

Open the contributing guide

Research direction

Start at the dayjs.duration entry point and review how duration strings are currently validated, including the inner regex and milliseconds() behavior mentioned in the issue. Define the expected isValid() result for valid and invalid duration examples, then add coverage for those cases and confirm the public duration API exposes the method.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
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.