1

Here is mine code to convert Arabic/Islamic/Hijri Date to English/Georgian Date Can anyone guide me how can i do inverse of it?

    public String ArabicToEnglish(String date){
        String [] sepratedString = ParseString(date);
        int day = Integer.parseInt(sepratedString[0]);
        int month = Integer.parseInt(sepratedString[1]);
        int year = Integer.parseInt(sepratedString[2]);

        double temp = (year-1)+(month-1)/12+(day-1)/354.3;
        temp*= 354.3/365.24;
        temp+=622.54;
        //find year
        year = (int) temp;
        temp = temp-year;
        //find month
        temp *= 12;
        double temp2 = temp;
        month = (int) temp;
        temp = temp - month;
        for(;;){
            if(temp2>temp2-month){
                month++;
            }else{
                break;
            }
        }
        temp *= 30.4167;
        day = (int) temp;


        return String.valueOf(day)+"-"+String.valueOf(month)+"-"+String.valueOf(year);
    }

I used this resource to get help : Link

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Muhammad Haseeb
  • 634
  • 5
  • 20
  • 1
    Without unit tests this code can't be trusted. This sort of stuff is notoriously tricky to get right. If you need to do the inverse, well, start trying. – tadman Dec 08 '17 at 19:33
  • Could you please specify?? Where to start trying? Would be thankful – Muhammad Haseeb Dec 08 '17 at 19:40
  • Interesting challenge. What’s your objection to using a good and well-tested library? – Ole V.V. Dec 08 '17 at 20:17
  • Problem set limits me to do not use any library. – Muhammad Haseeb Dec 09 '17 at 05:29
  • Here is a more robust accurate and safe method to convert any of the 5 Hijri Calendars to any of the 18 World Calendars without using external libraries or complex maths formulas: https://stackoverflow.com/questions/71222556/function-to-convert-any-of-5-islamic-hijri-calendars-dates-to-any-of-18-world – Mohsen Alyafei Feb 23 '22 at 08:36

0 Answers0