Skip to content

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

@jyasskin

Description

@jyasskin
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.

Activity

keithamus

keithamus commented on Mar 26, 2024

@keithamus
Contributor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @jyasskin@keithamus

      Issue actions

        precision=day should return "today" instead of "now" · Issue #279 · github/relative-time-element