Skip to content

feat(duration): parse time strings (HH:mm:ss) into durations - #3193

Open
hamzahamidi wants to merge 1 commit into
iamkun:devfrom
hamzahamidi:feat/duration-time-string-parsing
Open

feat(duration): parse time strings (HH:mm:ss) into durations#3193
hamzahamidi wants to merge 1 commit into
iamkun:devfrom
hamzahamidi:feat/duration-time-string-parsing

Conversation

@hamzahamidi

@hamzahamidi hamzahamidi commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

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:

dayjs.duration('02:04:33')
dayjs.duration('23:59')
dayjs.duration('7.23:59:59')
dayjs.duration('23:59:59.999')
dayjs.duration('-23:59:59')

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:mm
  • HH:mm:ss
  • days.HH:mm:ss
  • fractional seconds, e.g. 23:59:59.999
  • signed values, e.g. -23:59:59

Fractional 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:

dayjs.duration('02:04:33')

The two-argument form from #1146:

dayjs.duration('02:04:33', 'HH:mm:ss')

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
  • 36 tests passed (6 new, 30 existing)
  • Full Lint and Unit Test GitHub Actions workflow passes

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Durations: Convert HH:MM:SS string to seconds

1 participant