luxon icon indicating copy to clipboard operation
luxon copied to clipboard

clarify Interval formatting doc (and/or improve Interval formatting)

Open wkeese opened this issue 5 years ago • 2 comments

The doc on https://moment.github.io/luxon/docs/class/src/interval.js~Interval.html states that:

To convert the Interval into other representations, see toString, toISO, toISODate, toISOTime, toFormat, and toDuration.

However, the link to toFormat() goes to the DateTime documentation page (it took me a while to realize this), and that page says:

You may not want this. See toLocaleString for a more flexible formatting tool.

But Interval.toLocaleString() actually prints out ISO format.

I realize as written in #325 that range formatting isn't supported properly, so this ticket can be just about updating the doc... although I do wonder why you don't use Intl.formatRange() and then when unsupported, fallback to interval.start.toLocalString(options) + " - " + interval.end.toLocalString(options).

wkeese avatar Apr 13 '20 22:04 wkeese

Yeah, that's probably just copied and pasted from the DateTime one. I agree the doc should be fixed.

I completely agree about formatRange() and the fallback; I actually hadn't realized that formatRange was implemented anywhere. It seems to work for me in at least Chrome though. Would take a PR for that.

icambron avatar Apr 14 '20 03:04 icambron

The doc fixes are already on the 2.0 branch, commits 6273a494 and 4ece63b0.

formatRange is only available on Chrome according to CanIUse, which accounts for 64% of users.

GillesDebunne avatar Aug 20 '20 14:08 GillesDebunne