moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.05k stars 730 forks source link

Persian Calendar with Luxon #1586

Closed mohammadfereydooni closed 3 months ago

mohammadfereydooni commented 5 months ago

Hello, I'm using Luxon library for handling dates in my project. Unfortunately, the dates I receive through Luxon don't seem to be converted to Persian, even with the outputCalendar: 'persian' setting. Is there any solution or suggestion for using the Persian calendar with Luxon?

Thank you

icambron commented 5 months ago

@mohammadfereydooni can you give examples?

I'm not deeply familiar with the Persian calendar, but it seems to work for me:

DateTime.now().reconfigure({ outputCalendar: "persian" }).toLocaleString() // => '11/4/1402 AP'
DateTime.now().reconfigure({ outputCalendar: "persian" }).toLocaleString({ month: "long", day: "numeric", year: "numeric" }) // => 'Bahman 4, 1402 AP'
DateTime.now().reconfigure({ outputCalendar: "persian", locale: "fa" }).toLocaleString() // => '۱۴۰۲/۱۱/۴'

If you go here, open the dev tools and try the above (you'll need to run DateTime = luxon.DateTime first), you should see the same thing.