#ifndef DATE_TIME_H #define DATE_TIME_H #include #include #include #include class DateTime { public: static DateTime now() { return DateTime(time(NULL)); } DateTime(): theTime(0) {} explicit DateTime(time_t t): theTime(t) {} DateTime(int Y, int M, int D, int h, int m, int s); friend DateTime operator+(const DateTime& t1, time_t t2) { return DateTime(t1.theTime + t2); } const DateTime& operator+=(time_t t2) { theTime += t2; return *this; } void get(int& year, int& month, int& mday, int& hour, int& min, int& sec) const; std::string getString(char typ = 'h') const; const DateTime& operator-=(time_t t2) { theTime -= t2; return *this; } friend DateTime operator-(const DateTime& t1, time_t t2) { return DateTime(t1.theTime - t2); } friend bool operator<(const DateTime& t1, const DateTime& t2) { return t1.theTime < t2.theTime; } friend bool operator<=(const DateTime& t1, const DateTime& t2) { return t1.theTime <= t2.theTime; } friend bool operator==(const DateTime& t1, const DateTime& t2) { return t1.theTime == t2.theTime; } friend bool operator!=(const DateTime& t1, const DateTime& t2) { return t1.theTime != t2.theTime; } friend bool operator>(const DateTime& t1, const DateTime& t2) { return t1.theTime > t2.theTime; } friend bool operator>=(const DateTime& t1, const DateTime& t2) { return t1.theTime >= t2.theTime; } bool match(const std::set& Y, const std::set& M, const std::set& D, const std::set& W, const std::set& h, const std::set& m, const std::set& s) const; private: static bool match(const std::set& v, int v2) { return (v.empty()) || (v.count(v2) > 0); } static std::string toString2(int v); time_t theTime; }; #endif