Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precision=day should return "today" instead of "now" #279

Closed
jyasskin opened this issue Mar 26, 2024 · 1 comment · Fixed by #280
Closed

precision=day should return "today" instead of "now" #279

jyasskin opened this issue Mar 26, 2024 · 1 comment · Fixed by #280

Comments

@jyasskin
Copy link
Contributor

https://jsfiddle.net/oabcw7mz/ has an example of trying to render (now - 23 hours) with a precision of days, which should show "today" but actually shows "now".

I think the fix will involve making getRelativeTimeUnit

export function getRelativeTimeUnit(
duration: Duration,
opts?: Partial<RoundingOpts>,
): [number, Intl.RelativeTimeFormatUnit] {
const rounded = roundToSingleUnit(duration, opts)
if (rounded.blank) return [0, 'second']
for (const unit of unitNames) {
if (unit === 'millisecond') continue
const val = rounded[`${unit}s` as keyof Duration] as number
if (val) return [val, unit]
}
return [0, 'second']
}

return the precision unit for empty durations.

@keithamus
Copy link
Member

keithamus commented Mar 26, 2024

Sounds like you have a good handle on the problem. Would you like to make a PR?

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 a pull request may close this issue.

2 participants