// src/Date.hh // This file is part of libpbe; see http://decimail.org // (C) 2006 Philip Endecott // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef libpbe_Date_hh #define libpbe_Date_hh #include #include #include namespace pbe { static int days_in_month_[] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; struct Date { uint16_t year; uint8_t month; uint8_t day; Date() {} Date(int year_, int month_, int day_): year(year_), month(month_), day(day_) {} Date(time_t t) { struct tm b; localtime_r(&t, &b); year = b.tm_year + 1900; month = b.tm_mon + 1; day = b.tm_mday; } bool operator<(const Date& rhs) const { return (year1) { --day; } else { if (month>1) { --month; } else { month=12; --year; } day = days_in_month(); } return *this; } }; inline std::ostream& operator<<(std::ostream& strm, Date d) { strm << d.year << "-" << static_cast(d.month) << "-" << static_cast(d.day); return strm; } } #endif