Unable to parse some Umm Al-Qura dates in java, getting Invalid Hijrah day of month error

120 Views Asked by At

I am trying to parse below date in java using normal, hijri and Ummalqura calenders but everytime getting the same exception as below

Date: "30-02-1405" or "30-12-1419"

DateTimeException: Invalid Hijrah day of month: 30

Note: There are many other date which are causing the same issue.

To me, it seems like i am not able to pass the calendar type correctly to the calender function. Can anyone help me parsing these dates.

Below are the code i tried

// Using the msarhan ummalqura-calendar library

Locale en = Locale.ENGLISH;
        
UmmalquraCalendar calnow = new UmmalquraCalendar(en);

calnow.set(1419, UmmalquraCalendar.THUL_HIJJAH, 30);
        
System.out.println(calnow.getTime());
// Using Java time HijrahChronology

HijrahDate dateOfBirthHijri = HijrahChronology.INSTANCE.date(1405, 2, 30);
1

There are 1 best solutions below

3
Anish B. On

THUL_HIJJAH (December) (year 1419) and SAFAR (February) (year 1405) has only 29 days .

So, the dates: "30-02-1405", "30-12-1419" are invalid. Use 29th day instead.

Update to this:

    Locale en = Locale.ENGLISH;

    UmmalquraCalendar calnow = new UmmalquraCalendar(en);

    calnow.set(1419, UmmalquraCalendar.THUL_HIJJAH, 29);

    System.out.println(calnow.getTime());

Or

HijrahDate dateOfBirthHijri = HijrahChronology.INSTANCE.date(1405, 2, 29);
System.out.println(dateOfBirthHijri);

Output:

> Task :Example.main()
Fri Apr 16 19:03:34 IST 1999
Hijrah-umalqura AH 1405-02-29