73 lines
1.6 KiB
C++
73 lines
1.6 KiB
C++
#include "Date.hpp"
|
|
#include <string>
|
|
|
|
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;
|
|
|
|
#ifdef __APPLE__
|
|
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;
|
|
} |