Home > libalgo > 日付関係

日付関係

概要

英語の綴りとツェラーの公式.

使い方

曜日が知りたいときは day[(zeller(y,m,d)+1)%7] とする.オーバーフローに注意.

実装

const std::string day[] = {"Sunday",   "Monday", "Tuesday", "Wednesday",
                           "Thursday", "Friday", "Saturday"};

const std::string month[] = {"January", "February", "March",     "April",   "May",      "June",
                             "July",    "August",   "September", "October", "November", "December"};

const int month_length[] = {31, 28 /* <- 29 if is uruu */, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

long long zeller(long long y, long long m, long long d) {
    if (m <= 2) y--, m += 12;
    return (365 * y) + (y / 4) - (y / 100) + (y / 400) + (306 * (m + 1)) / 10 + d - 429;
}

bool is_uruu(int y) { return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); }