Skip to content

fix: duration humanize ignores leap years (fixed-unit decomposition) - #3172

Open
Jerryyy985 wants to merge 1 commit into
iamkun:devfrom
Jerryyy985:fix-3170-duration-humanize
Open

fix: duration humanize ignores leap years (fixed-unit decomposition)#3172
Jerryyy985 wants to merge 1 commit into
iamkun:devfrom
Jerryyy985:fix-3170-duration-humanize

Conversation

@Jerryyy985

Copy link
Copy Markdown

Summary

humanize() added the fixed-365-day $ms to a real calendar date and diffed it via fromNow, so durations computed with fixed units drifted with the calendar — dayjs.duration('P9999Y').humanize() rendered '9992 years', and results varied with the current date (leap-year position).

Fix

Decompose $ms into fixed units (MILLISECONDS_A_YEAR etc., the same basis as asYears) and format through the relativeTime locale templates, reproducing the threshold chain exactly (including the 'M' no-d field and abs<=1 fallback).

  • P9999Y'9999 years' (was '9992 years')
  • Month/year results are date-independent and match moment.js (P18M'2 years')
  • Works without the relativeTime plugin (old implementation threw)

Fixes #3170

humanize() added the fixed-365-day $ms to a real calendar date and diffed it,
so durations computed with fixed units drifted with the calendar (P9999Y ->
'9992 years', and results varied with the current date).

Fix: decompose $ms into fixed units (MILLISECONDS_A_YEAR etc., same basis as
asYears) and format via the relativeTime locale templates, reproducing the
threshold chain exactly. P9999Y now renders '9999 years'; month/year results
are date-independent and match moment.js.

Fixes iamkun#3170
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.

duration humanize ignoring leap years

1 participant