Luxon: Relative time shows `in 0 seconds`

Created on 24 Mar 2019  路  8Comments  路  Source: moment/luxon

Relative time shows in 0 seconds for "now" dates. Instead it should display: 'Just now'

All 8 comments

Unfortunately this is determined by the Intl API, not Luxon, so there鈥檚 no way to change that. I can鈥檛 override it because Luxon doesn鈥檛 have that string in every language

I have the same issue and I understand @icambron statement, but can we discuss at least a workaround? Is this being discussed for Intl API somewhere?

Workaround:

const relativeTime = DateTime.fromISO(time).toRelative()
return relativeTime === 'in 0 seconds' ? 'Just now' : relativeTime

locale-agnostic workaround:

export function toRelative(date: Date) {
  if (DateTime.fromJSDate(date).diffNow().as('seconds') > -30) return 'just now';
  return DateTime.fromJSDate(date).toRelative();
}

@seavan That's not locale-agnostic, though, because "just now" is an English string

i am saying "locale-agnostic" because it will not break if locale is not 'en' (and toRelative returns something which doesn't have a string 'in 0 seconds there') it is still useful - but you do need to localize 'just now' within your own app, that's true.

If luxon is going to use the Intl API and not try to work around some of its shortcomings then it should at least keep issues like this open until it is resolved in the API so it has a better chance of being found by anyone who needs a work around.

@UziTech no, the list of issues is the only tool I have to manage the things I actually can fix, and I'm arguably not even able to keep up with that. I can't have a big list of tickets sitting around waiting for browsers to update.

Was this page helpful?
0 / 5 - 0 ratings