moment / luxon

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

native islamic date as input date #1433

Closed mmyassin closed 1 year ago

mmyassin commented 1 year ago

Describe the bug when i have an islamic date as input "1444-10-19T00:00:00" i expect the formted result output "Shawwal 19, 1444 AH" but i get "Jumada II 28, 848 AH" which is completely wrong date any ideas how to handle dates when the input date is not an gregorian date

To Reproduce Settings.defaultOutputCalendar = "islamic"; console.log(DateTime.fromISO("1444-10-19T00:00:00").toLocaleString(DateTime.DATETIME_FULL));

Actual vs Expected behavior input: "1444-10-19T00:00:00" expected: "Shawwal 19, 1444 AH" actual: "Jumada II 28, 848 AH"

Alban-i commented 1 year ago

Salam aleykoum,

I don't think it's an issue with Luxon. You set up the default output to be hijri.

Actually, your input is hijri but Luxon understands as gregorian.

You should explore something like this:

const { DateTime } = require('luxon');
const moment = require('moment-hijri');

const islamicDate = DateTime.fromISO('1444-10-19T00:00:00');
const gregorianDate = moment(islamicDate.toJSDate()).format('YYYY-MM-DD');

console.log('Gregorian date:', gregorianDate);
diesieben07 commented 1 year ago

@Alban-i is correct. Like the name suggests, outputCalendar controls the calendar for date output. Parsing always uses the Gregorian calendar: https://moment.github.io/luxon/#/calendars

Unless browsers add support for parsing dates in other calendars, doing so will be out of scope for Luxon.