Joda api not return proper islamic date

395 views Asked by At

I am converting Gregorian dates to Islamic dates. I am setting its leap year pattern to Indian leap year but it is not working.

I make for loop and Gregorian date which takes current month and count is days and convert it to Islamic date. What i want

Here is my code

        for(int i=0;i<maxDay;i++)
        {
            eng.add(String.valueOf(i+1));
            DateTime dtISO=new DateTime(currentY,currentMonth+1,i+1,0,0);
            DateTimeZone asia= DateTimeZone.forID("Asia/Riyadh");

            DateTime dtIslamic = dtISO.withChronology(
                    IslamicChronology.getInstance(
                              asia, 
                              IslamicChronology.LEAP_YEAR_INDIAN));
            String islamicDateArr="";
            split=dtIslamic.toString().split("T");
            split=split[0].split("-");
            if(i==0 || Integer.parseInt(split[2])==1)
            {
                isl.add(String.valueOf(split[2]+" "+islamicMonths[Integer.parseInt(split[1])-1]));
                continue;
            }
            isl.add(String.valueOf(split[2]));
        }
1

There are 1 answers

0
Meno Hochschild On

Your code seems to be correct.

Since you told me to have tried every of the four leap year patterns of Joda-Time without success I get the feeling there might be a bug or just a missing feature because among all supported leap year patterns there should be a pair of patterns which are different by one day (and you observe one day difference).

Other people have already submitted bug issues. See here:

issue 163

issue 107

As you can see it will be hard for you to convince the project leader to solve your problem for you. Maybe he is right when saying that Joda-Time has not a bug, but is just not complete.

Keep in mind that according to R.H. van Gent the calculated islamic calendar algorithm knows at least 8 instead of 4 variants because there are 4 intercalary schemes and (for each scheme) two variations depending on the precise start of the islamic epoch (Thursday versus Friday epoch). So Joda-Time is just not supporting all variants.

What are the alternatives to Joda-Time?

a) Java-8 and its backport Threeten-BP (for Java-6+7) support the table-driven Umalqura-calendar of Saudi-Arabia (sighting-based). I am not sure if this solves your problem however (if not then you might supply a hand-written file containing the table data relevant for you - a lot of work). Note that both libraries don't support algorithm-based islamic calendars.

b) Some people have written their own home-grown workarounds. I have found this hijri converter via Google. No idea if this works for you.

c) IBM offers a Hijri calendar in its ICU-project. It offers different leap year patterns than Joda-Time. Maybe it helps.

Side note: As you can see the current Java-support for Hijri calendars is not really satisfying. That is why I decided to set up a new implementation in my own library Time4J. It is scheduled for maybe 2-3 months later in autumn 2015.