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

Localise Interval output #325

Closed
klase opened this issue Sep 13, 2018 · 3 comments · Fixed by #1320
Closed

Localise Interval output #325

klase opened this issue Sep 13, 2018 · 3 comments · Fixed by #1320

Comments

@klase
Copy link

klase commented Sep 13, 2018

I've yet to find a way to properly localise interval output. Given an interval with start date 09/03/2018 and end date 09/10/2018, would it be possible to support localised output like the below using toLocaleString on an Interval object?

'September 3 - 10' for 'en-US'
'3 - 10 September' for 'en-GB'

or is this out of the scope for this library?

Thanks

@icambron
Copy link
Member

icambron commented Sep 13, 2018

I would love to do this but...it's complicated.

So first, remember that Luxon doesn't have any idea how to do localization itself; it just uses what the browser has built in, and there's no API for localizing things like intervals.

It still may be possible, though. I also maintain Twix, which is a Moment plugin that knows how to make nice strings like that (complicated, because it's "Sept 3-10", but "Sept 3 - Oct 10", etc), although not localized. I tried an experiment in Twix where I could take the localized date format and try to "zipper" it up based on that format instead of just based on hardcoded rules. It was unexpectedly complicated and I abandoned the effort.

So when it came time to do it here, I decided against it for three reasons:

  1. it's a fair amount of code to just get right in one language
  2. it requires me to impose a bunch of opinions, which didn't fit well in Luxon
  3. the localization would be super complicated

So I left it all out. I always thought I'd at least port the formatting parts of Twix to a Luxon plugin and maybe in the process finally finish the localization part, but I never did.

So yes, out of scope.

@klase
Copy link
Author

klase commented Sep 13, 2018

Makes sense. It's not a massive task to deal with this on a per case basis anyhow. Thanks for clarifying.

@wkeese
Copy link

wkeese commented Apr 13, 2020

Note that you can localize Interval output by leveraging Intl.DateTimeFormat.formatRange.

Sadly, that API is only currently supported on Chrome, although you could fallback to interval.start.toLocalString(options) + " - " + interval.end.toLocalString(options).

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.

3 participants