Skip to content

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

Closed
@jyasskin

Description

@jyasskin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions