Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi i had the code in server side for Gregorian date to Hijridate but for better performance i need it to be in client side ,so please post the code in javascript for this.
Posted 6-Mar-13 20:15pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

function gmod(n,m){
    return ((n%m)+m)%m;
}
 
function kuwaiticalendar(adjust){
    var today = new Date();
    if(adjust) {
        adjustmili = 1000*60*60*24*adjust;
        todaymili = today.getTime()+adjustmili;
        today = new Date(todaymili);
    }
    day = today.getDate();
    month = today.getMonth();
    year = today.getFullYear();
    m = month+1;
    y = year;
    if(m<3) {
        y -= 1;
        m += 12;
    }
 
    a = Math.floor(y/100.);
    b = 2-a+Math.floor(a/4.);
    if(y<1583) b = 0;
    if(y==1582) {
        if(m>10)  b = -10;
        if(m==10) {
            b = 0;
            if(day>4) b = -10;
        }
    }
 
    jd = Math.floor(365.25*(y+4716))+Math.floor(30.6001*(m+1))+day+b-1524;
 
    b = 0;
    if(jd>2299160){
        a = Math.floor((jd-1867216.25)/36524.25);
        b = 1+a-Math.floor(a/4.);
    }
    bb = jd+b+1524;
    cc = Math.floor((bb-122.1)/365.25);
    dd = Math.floor(365.25*cc);
    ee = Math.floor((bb-dd)/30.6001);
    day =(bb-dd)-Math.floor(30.6001*ee);
    month = ee-1;
    if(ee>13) {
        cc += 1;
        month = ee-13;
    }
    year = cc-4716;
 
    if(adjust) {
        wd = gmod(jd+1-adjust,7)+1;
    } else {
        wd = gmod(jd+1,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);
 
    var myRes = new Array(8);
 
    myRes[0] = day; //calculated day (CE)
    myRes[1] = month-1; //calculated month (CE)
    myRes[2] = year; //calculated year (CE)
    myRes[3] = jd-1; //julian day number
    myRes[4] = wd-1; //weekday number
    myRes[5] = id; //islamic date
    myRes[6] = im-1; //islamic month
    myRes[7] = iy; //islamic year

    return myRes;
}
function writeIslamicDate(adjustment) {
    var wdNames = new Array("Ahad","Ithnin","Thulatha","Arbaa","Khams","Jumuah","Sabt");
    var iMonthNames = new Array("Muharram","Safar","Rabi'ul Awwal","Rabi'ul Akhir",
    "Jumadal Ula","Jumadal Akhira","Rajab","Sha'ban",
    "Ramadan","Shawwal","Dhul Qa'ada","Dhul Hijja");
    var iDate = kuwaiticalendar(adjustment);
    var outputIslamicDate = wdNames[iDate[4]] + ", "
    + iDate[5] + " " + iMonthNames[iDate[6]] + " " + iDate[7] + " AH";
    return outputIslamicDate;
}
 

 

Credits to
http://www.al-habib.info/islamic-calendar/hijricalendartext.htm[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 395
1 Sergey Alexandrovich Kryukov 333
2 BillWoodruff 309
3 OriginalGriff 307
4 George Jonsson 275
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100