aspose file tools*
The moose likes Java in General and the fly likes Gregorian-Hijri Dates Converter JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Gregorian-Hijri Dates Converter JAVA" Watch "Gregorian-Hijri Dates Converter JAVA" New topic
Author

Gregorian-Hijri Dates Converter JAVA

Ghaith Shamayleh
Greenhorn

Joined: Apr 13, 2011
Posts: 14
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
Did you have a question or are you just sharing your code ?


Joanne
Ghaith Shamayleh
Greenhorn

Joined: Apr 13, 2011
Posts: 14
Am just sharing the code
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14433
    
  23

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?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ghaith Shamayleh
Greenhorn

Joined: Apr 13, 2011
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
Marshal

Joined: Mar 22, 2005
Posts: 42930
    
  68
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

Joined: Apr 13, 2011
Posts: 14
http://en.wikipedia.org/wiki/Islamic_calendar
http://en.wikipedia.org/wiki/Kuwaiti_algorithm
abu alfouz
Ranch Hand

Joined: Nov 20, 2006
Posts: 44
Very useful .. thank you


SCJP 1.5
SCWCD 1.4
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Aug 16, 2005
Posts: 14433
    
  23

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Gregorian-Hijri Dates Converter JAVA