unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
MIT License
56 stars 3 forks source link

Date range type #109

Open samhh opened 2 years ago

samhh commented 2 years ago

Example which is different to manually formatting as start – end:

> new Intl.DateTimeFormat('en-US-u-ca-buddhist').formatRange(new Date('1'), new Date('2'))
'1/1/2544 – 2/1/2544 BE'

I haven't been able to find a more common locale that differs however.

OliverJAsh commented 2 years ago

I haven't been able to find a more common locale that differs however.

How about this?

const longFormat = new Intl.DateTimeFormat("en", { dateStyle: "long" });
longFormat.formatRange(new Date('2020-10-01Z'), new Date('2020-10-20Z'))
// => 'October 1 – 20, 2020'