Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

Gregorian-Hijri Dates Converter JAVA

Ghaith Shamayleh
Greenhorn
Posts: 14

Joanne Neal
Rancher
Posts: 3742
16
Did you have a question or are you just sharing your code ?

Ghaith Shamayleh
Greenhorn
Posts: 14
Am just sharing the code

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15279
39
Ok, thanks then.

I do have some comments about the code. It contains a lot of "magic" numbers: 365.25, 4716, 30.6001, 1524, 2299160, 1867216.25, 36524.25, 122.1, 10631, 1948084, 1948085, 8.01, 28.5001, 29.5001, ...

What do all those numbers mean? How do you know this code works correctly? For which range of dates does it work correctly?

Ghaith Shamayleh
Greenhorn
Posts: 14
These numbers are used to calculate the Islamic Higri date, you can check if the date returned on the following site if its correct
http://www.islamicity.com/PrayerTimes/defaultHijriConv.asp

Ulf Dittmer
Rancher
Posts: 42967
73
365.25 in particular sounds suspicious - does this code handle leap years correctly in the long run?

Maybe you can provide a link to Wikipedia page or something like that where the topic (not necessarily the calculations) are explained.

Ghaith Shamayleh
Greenhorn
Posts: 14

abu alfouz
Ranch Hand
Posts: 44
Very useful .. thank you

Rob Spoor
Sheriff
Posts: 20527
54
ghaith shamayleh wrote:These numbers are used to calculate the Islamic Higri date, you can check if the date returned on the following site if its correct
http://www.islamicity.com/PrayerTimes/defaultHijriConv.asp

Then make them constants - private static final fields of the right type (int / double) with a descriptive name.

Campbell Ritchie
Sheriff
Posts: 48940
60
The duration of a year is not 365.25 days. According to this webpage that is 11min 14 seconds too long. anyway, using floating-point arithmetic is bound to cause imprecisions.

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15279
39
Campbell Ritchie wrote:The duration of a year is not 365.25 days. According to this webpage that is 11min 14 seconds too long. anyway, using floating-point arithmetic is bound to cause imprecisions.

It's much more complicated than that.

According to Wikipedia, a Julian year is 365.25 days. I guess that the definition on the above website is the length of a Gregorian year (a year according to the usual Gregorial calendar). But there are also other ways to define a year: for example a sidereal year, which is the time it takes the Earth to make exactly one orbit around the Sun, is slightly different (365 days, 6 hours 9 minutes, 9.7676 seconds). And there are other definitions which are again slightly different.