#include "Date.hpp" #include Date::Date() : time(0), _isAny(true){}; Date::Date(const time_t &_time) : time(_time), _isAny(false){}; Date::Date(const tm &_time) : _isAny(false) { tm temp = _time; this->time = mktime(&temp); } void Date::setNewDate(const time_t &newTime) { this->_isAny = false; this->time = newTime; } void Date::setNewDate(const tm &newTime) { this->_isAny = false; tm temp = newTime; this->time = mktime(&temp); } void Date::setAny() { this->time = 0; this->_isAny = true; } bool Date::isAny() const { return this->_isAny; } time_t Date::getTime() const { return this->time; } std::string Date::toString() const { if (this->_isAny) { return "[Any]"; } char buffer[20]; tm curTime; #if defined __APPLE__ || defined __linux__ curTime = *(localtime(&this->time)); #endif #if defined _WIN64 || defined _WIN32 localtime_s(&curTime, &this->time); #endif strftime(buffer, 20, "%F", &curTime); return std::string(buffer); } bool Date::operator<(const Date &otherDate) const { return (this->_isAny || otherDate._isAny) || this->time < otherDate.time; } bool Date::operator>(const Date &otherDate) const { return (this->_isAny || otherDate._isAny) || this->time > otherDate.time; } bool Date::operator<=(const Date &otherDate) const { return (this->_isAny || otherDate._isAny) || this->time <= otherDate.time; } bool Date::operator>=(const Date &otherDate) const { return (this->_isAny || otherDate._isAny) || this->time >= otherDate.time; } bool Date::operator==(const Date &otherDate) const { return (this->_isAny || otherDate._isAny) || this->time == otherDate.time; }