Last active
April 15, 2022 04:15
-
-
Save seyyah/ebe7c309d9a9a2baf4739b6c1faf4e21 to your computer and use it in GitHub Desktop.
Hijri To Greg http://www.islamicity.org/PrayerTimes/assets/js/prayertime.lib.js?ver=MHK-JUNE-12-2017-0.9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GregToHijri(arg) { | |
console.log ( 'arg' ); | |
console.log (arg); | |
if(arg == ""){ | |
return ""; | |
} | |
//declare a date format year,month,day sequence | |
var arabic_date = new Array(0,0,0); | |
var jd; | |
var jd1; | |
var l; | |
var j; | |
var n; | |
var d = parseInt(arg.getDate()); | |
var m = parseInt(arg.getMonth()+1); // date type start with 0 - 11, so we need adjust by +1 | |
var y = parseInt(arg.getFullYear()); | |
var deltaAdjusted; | |
deltaAdjusted = adjustDelta(m,y); | |
if ((y>1582)||((y==1582)&&(m>10))||((y==1582)&&(m==10)&&(d>14))) | |
{ | |
//added +delta on jd to comply isna rulling | |
jd = intPart((1461*(y+4800+intPart((m-14)/12)))/4)+intPart((367*(m-2-12*(intPart((m-14)/12))))/12)- | |
intPart( (3* (intPart( (y+4900+ intPart( (m-14)/12) )/100) ) ) /4)+d-32075 + deltaAdjusted; | |
} | |
else | |
{ | |
//added +delta on jd to comply isna rulling | |
jd = 367*y - intPart((7*(y+5001+intPart((m-9)/7)))/4) + intPart((275*m)/9)+d+1729777 + deltaAdjusted; | |
} | |
//arg.JD.value=jd | |
//added -delta on jd1 to comply isna rulling | |
jd1 = jd - deltaAdjusted; | |
//arg.wd.value=weekDay(jd1%7) | |
l = jd - 1948440 + 10632; | |
n = intPart((l-1)/10631); | |
l = l-10631*n + 354; | |
j = (intPart((10985-l)/5316))*(intPart((50*l)/17719))+(intPart(l/5670))*(intPart((43*l)/15238)); | |
l = l-(intPart((30-j)/15))*(intPart((17719*j)/50))-(intPart(j/16))*(intPart((15238*j)/43))+29; | |
m = intPart((24*l)/709); | |
d = l-intPart((709*m)/24); | |
y= 30 * n + j - 30; | |
arabic_date[2] = d; | |
arabic_date[1] = m; | |
arabic_date[0] = y; | |
return arabic_date; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function adjustDelta(m,y){ | |
// whenever there is an adjustment to be made | |
// ( be it for the current month or for a future month/date ), use this! | |
// add new cases, without deleting the previous ones | |
// make sure each case comes with its hijriToGreg and GregToHijri pairs ( ex: 1438 & 2017 ) | |
// note whenever you make changes to the scripts, update the version at /prayertimes/version-integer.php | |
var bingo = false; // this gets set to true only if there is an adjustment match and allow us to short-circuit the function | |
var returnVal = delta; // this is what comes from the config.js, if no adjustment match occurs, this prevails at the end of the function return | |
// ramadan 1438 fix | |
//----------------------------------------------------------------- | |
if ( ( m == 6 && y == 2017 ) || ( m == 9 && y == 1438 ) ) { | |
bingo = true; | |
returnVal = 0; | |
}; | |
if ( bingo ) { | |
return returnVal; | |
} | |
//----------------------------------------------------------------- | |
return returnVal; | |
} | |
/** Date conversion English to Arabic and Arabic to English months **/ | |
function intPart(floatNum){ | |
if (floatNum< -0.0000001){ | |
return Math.ceil(floatNum-0.0000001); | |
} | |
return Math.floor(floatNum+0.0000001); | |
} | |
/** Start: Holds arabic and englsih month names**/ | |
//return English month full name | |
function getEnglishMonthFullName(month) { | |
var monthName = new Array('January', 'February', 'March', 'April', 'May', 'June', | |
'July', 'August', 'September', 'October', 'November', 'December'); | |
return monthName[month]; | |
} | |
//return English month full name | |
function getEnglishMonthShortName(month) { | |
var monthName = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', | |
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); | |
return monthName[month]; | |
} | |
function getHijriMonthFullName(month) { | |
var monthName = new Array('Muharram', 'Safar', 'Rabi Al-Awwal', 'Rabi Al-Thani', 'Jumada Al-Awwal', 'Jumada Al-Thani' , 'Rajab', 'Sha`ban', 'Ramadan', 'Shawwal', 'Dhul-Qa`dah', 'Dhul-Hijjah'); | |
return monthName[month]; | |
} | |
function getHijriMonthName(month) { | |
var monthName = new Array('Muharram', 'Safar', 'Rabi Al-Awwal', 'Rabi Al-Thani', 'Jumada Al-Awwal', 'Jumada Al-Thani' , 'Rajab', 'Sha`ban', 'Ramadan', 'Shawwal', 'Dhul-Qa`dah', 'Dhul-Hijjah'); | |
return monthName[month]; | |
} | |
function getHijriMonthShortName(month) { | |
var monthName = new Array('Muharram', 'Safar', 'Rabi Al-Awwal', 'Rabi Al-Thani', 'Jumada Al-Awwal', 'Jumada Al-Thani' , 'Rajab', 'Sha`ban', 'Ramadan', 'Shawwal', 'Dhul-Qa`dah', 'Dhul-Hijjah'); | |
return monthName[month]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** set the offset **/ | |
var delta = 1; // this may get overwritten on the fly by js functions in prayer.lib.js depending on hijri to greg and greg to hijri and the manually edited array values | |
function HijriToGreg(arabicDate) { | |
console.log ( 'arabicDate' ); | |
console.log (arabicDate); | |
if(arabicDate == ""){ | |
return ""; | |
} | |
//declare a date format year,month,day sequence | |
var jd; | |
var jd1; | |
var l; | |
var j; | |
var n; | |
var wd; | |
var i; | |
var k; | |
var d = parseInt(arabicDate[2]); | |
var m = parseInt(arabicDate[1]); | |
var y = parseInt(arabicDate[0]); | |
var deltaAdjusted; | |
deltaAdjusted = adjustDelta(m,y); | |
var english_date = new Array(0,0,0); | |
//added delta=1 on jd to comply isna rulling for hajj 2007 | |
//delta = delta_array_hijri[arabicDate[1] - 1]; | |
jd = intPart((11*y+3)/30)+354*y+30*m-intPart((m-1)/2)+d+1948440-385-deltaAdjusted; | |
//arg.JD.value=jd | |
//wd = weekDay(jd % 7); // no use of this line | |
if (jd > 2299160 ) { | |
l = jd + 68569; | |
n = intPart((4*l)/146097); | |
l = l - intPart((146097*n+3)/4); | |
i = intPart((4000*(l+1))/1461001); | |
l = l-intPart((1461*i)/4)+31; | |
j = intPart((80*l)/2447); | |
d = l-intPart((2447*j)/80); | |
l = intPart(j/11); | |
m = j+2-12*l; | |
y = 100*(n-49)+i+l; | |
} else { | |
j = jd+1402; | |
k = intPart((j-1)/1461); | |
l = j-1461*k; | |
n = intPart((l-1)/365)-intPart(l/1461); | |
i = l-365*n+30; | |
j = intPart((80*i)/2447); | |
d = i-intPart((2447*j)/80); | |
i = intPart(j/11); | |
m = j+2-12*i; | |
y= 4*k+n+i-4716; | |
} | |
english_date[2] = d; | |
english_date[1] = m; | |
english_date[0] = y; | |
return english_date; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nowDate = new Date(); | |
var arabic_nowDate = GregToHijri(nowDate); | |
var monthsno = arabic_nowDate[1] <10 ? "(0"+arabic_nowDate[1]+")" : "("+arabic_nowDate[1]+")"; | |
var sm = getHijriMonthName(arabic_nowDate[1]-1)+monthsno+", "+arabic_nowDate[0]; | |
$("#prayerTimesByArabicMonth option:contains(" + sm + ")").attr('selected', 'selected'); | |
var arabicStartDate = new Array(arabicCurrentYear,arabicCurrentMonth,1); | |
var english_equvant_start_date = HijriToGreg(arabicStartDate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
The adjustDelta function.
Can this:
if ( ( m == 6 && y == 2017 ) || ( m == 9 && y == 1438 ) ) { bingo = true; returnVal = 0; }; if ( bingo ) { return returnVal; }
be replaced with this:
if ( ( m == 6 && y == 2017 ) || ( m == 9 && y == 1438 ) ) return 0;
and how I know which pairs to add until, say, year 2050?