pikaday.js
/*
  This function determines if the Jalaali (Persian) year is
  leap (366-day long) or is the common year (365 days), and
  finds the day in March (Gregorian calendar) of the first
  day of the Jalaali year (jy).
  @param jy Jalaali calendar year (-61 to 3177)
  @return
    leap: number of years since the last leap year (0 to 4)
    gy: Gregorian year of the beginning of Jalaali year
    march: the March day of Farvardin the 1st (1st day of jy)
  @see: http://www.astro.uni.torun.pl/~kb/Papers/EMP/PersianC-EMP.htm
  @see: http://www.fourmilab.ch/documents/calendar/
*/
This function determines if the Jalaali (Persian) year is
leap (366-day long) or is the common year (365 days), and
finds the day in March (Gregorian calendar) of the first
day of the Jalaali year (jy).
This function determines if the Jalaali ( Persian ) year is leap ( 366 - day long ) or is the common year ( 365 days ) and finds the day in March ( Gregorian calendar ) of the first day of the Jalaali year ( jy ) .
function jalCal(jy) {
    var breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210
        , 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178
    ]
        , bl = breaks.length
        , gy = jy + 621
        , leapJ = -14
        , jp = breaks[0]
        , jm
        , jump
        , leap
        , leapG
        , march
        , n
        , i
    if (jy < jp || jy >= breaks[bl - 1])
        throw new Error('Invalid Jalaali year ' + jy)
    for (i = 1; i < bl; i += 1) {
        jm = breaks[i]
        jump = jm - jp
        if (jy < jm)
            break
        leapJ = leapJ + div(jump, 33) * 8 + div(mod(jump, 33), 4)
        jp = jm
    }
    n = jy - jp
    leapJ = leapJ + div(n, 33) * 8 + div(mod(n, 33) + 3, 4)
    if (mod(jump, 33) === 4 && jump - n === 4)
        leapJ += 1
    leapG = div(gy, 4) - div((div(gy, 100) + 1) * 3, 4) - 150
    march = 20 + leapJ - leapG
    if (jump - n < 6)
        n = n - jump + div(jump + 4, 33) * 33
    leap = mod(mod(n + 1, 33) - 1, 4)
    if (leap === -1) {
        leap = 4
    }
    return {
        leap: leap
        , gy: gy
        , march: march
    }
}
function jalCal ( jy ) { var breaks = [ - 61 , 9 , 38 , 199 , 426 , 686 , 756 , 818 , 1111 , 1181 , 1210 , 1635 , 2060 , 2097 , 2192 , 2262 , 2324 , 2394 , 2456 , 3178 ] , bl = breaks . length , gy = jy + 621 , leapJ = - 14 , jp = breaks [ 0 ] , jm , jump , leap , leapG , march , n , i if ( jy < jp || jy >= breaks [ bl - 1 ] ) throw new Error ( 'Invalid Jalaali year ' + jy ) for ( i = 1 ; i < bl ; i += 1 ) { jm = breaks [ i ] jump = jm - jp if ( jy < jm ) break leapJ = leapJ + div ( jump , 33 ) * 8 + div ( mod ( jump , 33 ) , 4 ) jp = jm } n = jy - jp leapJ = leapJ + div ( n , 33 ) * 8 + div ( mod ( n , 33 ) + 3 , 4 ) if ( mod ( jump , 33 ) === 4 && jump - n === 4 ) leapJ += 1 leapG = div ( gy , 4 ) - div ( ( div ( gy , 100 ) + 1 ) * 3 , 4 ) - 150 march = 20 + leapJ - leapG if ( jump - n < 6 ) n = n - jump + div ( jump + 4 , 33 ) * 33 leap = mod ( mod ( n + 1 , 33 ) - 1 , 4 ) if ( leap === - 1 ) { leap = 4 } return { leap : leap , gy : gy , march : march } }
This function determines if the Jalaali (Persian) year is
leap (366-day long) or is the common year (365 days), and
finds the day in March (Gregorian calendar) of the first
day of the Jalaali year (jy).
This function determines if the Jalaali ( Persian ) year is leap ( 366 - day long ) or is the common year ( 365 days ) and finds the day in March ( Gregorian calendar ) of the first day of the Jalaali year ( jy ) .
// Jalaali years starting the 33-year rule. // Find the limiting years for the Jalaali year jy. // Find the number of leap years from AD 621 to the beginning // of the current Jalaali year in the Persian calendar. // And the same in the Gregorian calendar (until the year gy). // Determine the Gregorian date of Farvardin the 1st. // Find how many years have passed since the last leap year.