Tags:
create new tag
view all tags

Date computations

/* Returns the day number of a date */
int Date::dayNumber() {
    int m = (month + 9) % 12;
    int y = year - m / 10;
    return 365 * y + y / 4 - y / 100 + y / 400 + (m * 306 + 5) / 10 + (day - 1);
}

/* Returns the date of a day number (g) */
void Date::dateFromNumber(int g) {
    year = (10000 * g + 14780) / 3652425;
    int ddd = g - (365 * year + year / 4 - year / 100 + year / 400);
    if (ddd < 0) {
        year = year - 1;
        ddd = g - (365 * year + year / 4 - year / 100 +year / 400);
    }
    int mi = (100 * ddd + 52) / 3060;
    month = (mi + 2) % 12 + 1;
    year = year + (mi + 2) / 12;
    day = ddd - (mi * 306 + 5) / 10 + 1;
}


Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2018-03-29 - JimSkon
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback