feat(duration): parse time strings (HH:mm:ss) into durations - #3193
Open
hamzahamidi wants to merge 1 commit into
Open
feat(duration): parse time strings (HH:mm:ss) into durations#3193hamzahamidi wants to merge 1 commit into
hamzahamidi wants to merge 1 commit into
Conversation
Matches moment.js behavior for creating durations from colon-separated time strings: HH:mm:ss, HH:mm, days.HH:mm:ss, and fractional seconds. Closes iamkun#1146
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for Moment-compatible colon-separated duration string parsing to the duration plugin. Closes #1146.
This lets Day.js parse duration strings such as:
Changes
When ISO 8601 duration parsing does not match a string input, Day.js now tries the same colon-separated duration syntax supported by Moment.js:
HH:mmHH:mm:ssdays.HH:mm:ss23:59:59.999-23:59:59Fractional seconds are converted to milliseconds so existing duration accessors such as
.seconds()and.milliseconds()continue to behave correctly.Scope
This PR adds Moment-compatible duration string syntax parsing; it does not attempt to make all Day.js duration behavior identical to Moment.js.
Parsing is automatic for the single-argument form:
The two-argument form from #1146:
is intentionally not added. In Day.js, the second argument is already the duration
unit, and Moment.js also supports these colon-separated strings through automatic single-argument detection.Validation
npx jest test/plugin/duration.test.js