src/Date.cpp
/*!
    Converts julian day to date.
*/
Converts julian day to date.
Converts julian day to date .
Date Date::fromJulianDay(std::int64_t julianDay)
{
    std::int64_t a = julianDay + 32044;
    std::int64_t b = floordiv(4 * a + 3, 146097);
    std::int64_t c = a - floordiv(146097 * b, 4);
    std::int64_t d = floordiv(4 * c + 3, 1461);
    std::int64_t e = c - floordiv(1461 * d, 4);
    std::int64_t m = floordiv(5 * e + 2, 153);
    int day = static_cast<int>(e - floordiv(153 * m + 2, 5) + 1);
    int month = static_cast<int>(m + 3 - 12 * floordiv(m, 10));
    int year = static_cast<int>(100 * b + d - 4800 + floordiv(m, 10));
    if (year <= 0)
        --year;
    return Date(year, month, day);
}
Date Date :: fromJulianDay ( std :: int64_t julianDay ) { std :: int64_t a = julianDay + 32044 ; std :: int64_t b = floordiv ( 4 * a + 3 , 146097 ) ; std :: int64_t c = a - floordiv ( 146097 * b , 4 ) ; std :: int64_t d = floordiv ( 4 * c + 3 , 1461 ) ; std :: int64_t e = c - floordiv ( 1461 * d , 4 ) ; std :: int64_t m = floordiv ( 5 * e + 2 , 153 ) ; int day = static_cast < int > ( e - floordiv ( 153 * m + 2 , 5 ) + 1 ) ; int month = static_cast < int > ( m + 3 - 12 * floordiv ( m , 10 ) ) ; int year = static_cast < int > ( 100 * b + d - 4800 + floordiv ( m , 10 ) ) ; if ( year <= 0 ) -- year ; return Date ( year , month , day ) ; }
Converts julian day to date.
Converts julian day to date .
/*
     * Math from The Calendar FAQ at http://www.tondering.dk/claus/cal/julperiod.php
     * This formula is correct for all julian days, when using mathematical integer
     * division (round to negative infinity), not c++11 integer division (round to zero)
     */ // Adjust for no year 0