Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gregorian-Hijri Dates Converter JAVA

 
Ghaith Shamayleh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have a question or are you just sharing your code ?
 
Ghaith Shamayleh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am just sharing the code
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15279
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very useful .. thank you
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic