Skip to content

Conversation

@bhavyajain-glitch
Copy link

Hi maintainers!

This PR adds a round: false option to duration.humanize() to allow for unrounded, precise output.

Closes: #2970

Summary
Updated duration.humanize() to accept an options object for { round: false } and { withSuffix: true }.

If round: false is passed, it now bypasses the relativeTime thresholds and formats the string manually.

If no options are passed, it defaults to the original, rounding behavior (fully backward-compatible).

Added ss: '%d seconds' to the relativeTime plugin for the new "10 seconds" output.

Added full tests for the new feature, backward compatibility, and fallbacks, maintaining 100% test coverage.

I'm a student working on a university project to learn open source, and I'd be happy to make any changes you suggest. Thanks!

Copy link

@michaelhazan michaelhazan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not a maintainer but i do feel these changes should be applied...

Comment on lines +318 to +319
expect(dayjs.duration({ seconds: 1 }).humanize({ round: false }))
.toBe('a few seconds')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like if we say

dayjs.duration({ seconds: 1 }).humanize({ round: false })

it should be a second, to be consistent with

dayjs.duration({ minutes: 1 }).humanize({ round: false })

being a minute

same applies to withSuffix: true

.locale(this.$l)
.fromNow(!withSuffix)
humanize(options) {
let withSuffix = false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like withSuffix should rather be interval, referring to it being a time interval.

after all this isn't necessarily a suffix, it changes the entire sentence, not only the end of it.

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.

[Feature request] Disable rounding in dayjs.duration().humanize()

3 participants