src/qk_datetime.c
/* Rata Die algorithm by Peter Baum */
Rata Die algorithm by Peter Baum
Rata Die algorithm by Peter Baum
static void
rdn_to_ymd(uint32_t rdn, uint16_t *yp, uint16_t *mp, uint16_t *dp, uint16_t *yday) {
    uint32_t Z, H, A, B;
    uint16_t y, m, d, doy ;
    rdn++;
    Z = rdn + 306;
    H = 100 * Z - 25;
    A = H / 3652425;
    B = A - (A >> 2);
    y = (100 * B + H) / 36525;
    d = B + Z - (1461 * y >> 2);
    m = (535 * d + 48950) >> 14;
    if (m > 12)
        y++, m -= 12, doy = d - 306;
    else
        doy = d + 59 + ((y & 3) == 0 && (y % 100 != 0 || y % 400 == 0));
    *yp = y;
    *mp = m;
    *dp = d - DayOffset[m];
    if(yday) *yday = doy;
}
static void rdn_to_ymd ( uint32_t rdn , uint16_t * yp , uint16_t * mp , uint16_t * dp , uint16_t * yday ) { uint32_t Z , H , A , B ; uint16_t y , m , d , doy ; rdn ++ ; Z = rdn + 306 ; H = 100 * Z - 25 ; A = H / 3652425 ; B = A - ( A >> 2 ) ; y = ( 100 * B + H ) / 36525 ; d = B + Z - ( 1461 * y >> 2 ) ; m = ( 535 * d + 48950 ) >> 14 ; if ( m > 12 ) y ++ , m -= 12 , doy = d - 306 ; else doy = d + 59 + ( ( y & 3 ) == 0 && ( y % 100 != 0 || y % 400 == 0 ) ) ; * yp = y ; * mp = m ; * dp = d - DayOffset [ m ] ; if ( yday ) * yday = doy ; }
Rata Die algorithm by Peter Baum
Rata Die algorithm by Peter Baum
/* day of year 1..366*/