Jump to content

Islamic Calendar


SYEDHANIF

Recommended Posts

hii need to develop an Islamic Calendar using Asp & JavaScript can any one have done before islamic calendar using asp please help me i am stuck i don't knowwhat i need to do is Display the Current date in Islamic Date FormatExample:Today Current Date Is: MAY 10, 2006It should display in Islamic Date Formate Like this: Rabi` Al-Thani 12, 1427 i.e the Current Date in Islamic Date Formateany idea please let me knowwarms regardssyed

Link to comment
Share on other sites

I've been looking over the wikipedia page, and it looks like the Islamic Calendar is pretty similar to the Gregorian. I guess the question is how do you convert between the two?I guess what I see is that this is a difficult problem, because the months in the Islamic Calendar start whenever the council says they start, so there's no algorithm to predict when that will happen. I guess the best thing that can be used is something like this:http://en.wikipedia.org/wiki/Tabular_Islamic_calendarThere is also this converter:http://www.phys.uu.nl/~vgent/islam/islam_tabcal.htmSo, here is the javascript date object:http://www.w3schools.com/jsref/jsref_obj_date.asphttp://devguru.com/technologies/javascript/10585.aspYou will need to use that object to help you out. So here is how you get the current date:

var now = new Date();var cur_year = now.getFullYear();var cur_month = now.getMonth(); //jan = 0, dec = 11var cur_date = now.getDate(); //day of month

The first thing we need to do is calculate the date in terms of how many days have passed. So we need to set up some date arrays, for the number of days in each Gregorian month:

var months_g = new Array();months_g[0] = 31;months_g[1] = 28;months_g[2] = 31;months_g[3] = 30;months_g[4] = 31;months_g[5] = 30;months_g[6] = 31;months_g[7] = 31;months_g[8] = 30;months_g[9] = 31;months_g[10] = 30;months_g[11] = 31;

And also for the leap years in the Islamic 30-year cycle:

var leap_years = new Array();for (i = 0; i <= 31; i++)  leap_years[i] = false;leap_years[2] = true;leap_years[5] = true;leap_years[7] = true;leap_years[10] = true;leap_years[13] = true;leap_years[16] = true;leap_years[18] = true;leap_years[21] = true;leap_years[24] = true;leap_years[26] = true;leap_years[29] = true;

Now we calculate how many days have passed since 1/1/0:

var total_days_g = Math.floor(cur_year * 365.25);for (i = 0; i < cur_month; i++)  total_days_g += months_g[i];total_days_g += cur_date;

Since the Islamic calendar started in 622, we have to subtract 622 years worth of days.

total_days_g -= Math.floor(622 * 365.25);

OK, I'm running into problems with how this is working out, I don't think I'm doing it right and I don't have the knowledge about the different calendars. I found that online converter I linked to above though, so I was looking at that code. To calculate the 'Kuwaiti algorithm' version of the date, I have taken out the code and modified it a little bit. Whoever programmed it was apparently trying to obfuscate the code, because it's not easy to follow with all the single letter variable names. If you can make sense of it that's cool, but I don't know the calendars well enough to understand what the calculations mean.

now = new Date();day = now.getDate();month = now.getMonth();year = now.getFullYear();jgc = 0;m = month + 1;y = year;if(m < 3){  m = m + 12;  y = y - 1;}c = Math.floor(y / 100.);if (y == 1582 && m > 10)  jgc = 10;if (y > 1582)  jgc = 2 - c + Math.floor(c/4.);jd = Math.floor(365.25*(y+4716)) + Math.floor(30.6001*(m+1)) + day + jgc - 1524;jgc = 0;if (jd > 2299160){  c = Math.floor((jd - 1867216.25) / 36524.25);  jgc =- (1 + c-Math.floor(c/4.));}b = jd - jgc + 1524;cc = Math.floor((b-122.1)/365.25);d = Math.floor(365.25*cc);month = Math.floor((b-d)/30.6001);day = (b-d) - Math.floor(30.6001*month);if (month > 13){  cc = cc + 1;  month = month - 12;}year = cc - 4716;month = month - 1;wd = Math.floor((Math.floor((jd+1.)%7.)+7.)%7.)+1;iyear = 10631./30.;epochastro = 1948084;epochcivil = 1948085;shift1 = 8.01/60.;z = jd - epochastro;cyc = Math.floor(z/10631.);z = z - 10631 * cyc;j = Math.floor((z-shift1)/iyear);iy = 30 * cyc + j;z = z - Math.floor(j*iyear+shift1);im = Math.floor((z+28.5001)/29.5);if (im == 13)   im=12;id = z - Math.floor(29.5001*im-29);day_islam = id;month_islam = im; //muharram = 1, zil hijjah = 12year_islam = iy;

Link to comment
Share on other sites

Yeah, it is confusing. This is the problem:

Each month has either 29 or 30 days, but usually in no discernible order. Traditionally, the first day of each month was the day (beginning at sunset) of the first sighting of the lunar crescent (the hilal) shortly after sunset. If the hilal was not observed immediately after the 29th day of a month, either because clouds blocked its view or because the western sky was still too bright when the moon set, then the day that began at that sunset was the 30th. Such a sighting had to be made by one or more trustworthy men testifying before a committee of Muslim leaders.
I'm not sure how to write an algorithm to determine when a trustworthy man is going to see a crescent moon. I don't really understand how a society can plan ahead with something like this. If you tell someone to meet you somewhere on the 20th in two months, that could be like 3 different days, depending on how many trustworthy men are stargazing.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...