60 lines
1.3 KiB
C++
60 lines
1.3 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;
|
|
}
|
|
|
|
time_t Date::getTime() const {
|
|
return this->time;
|
|
}
|
|
|
|
std::string Date::toString() const {
|
|
if (this->isAny) {
|
|
return "[Any]";
|
|
}
|
|
char buffer[20];
|
|
strftime(buffer, 20, "%F", localtime(&this->time));
|
|
return std::string(buffer);
|
|
}
|
|
|
|
bool Date::operator<(const Date &otherDate) const {
|
|
return this->isAny || this->time < otherDate.time;
|
|
}
|
|
|
|
bool Date::operator>(const Date &otherDate) const {
|
|
return this->isAny || this->time > otherDate.time;
|
|
}
|
|
|
|
bool Date::operator<=(const Date &otherDate) const {
|
|
return this->isAny || this->time <= otherDate.time;
|
|
}
|
|
|
|
bool Date::operator>=(const Date &otherDate) const {
|
|
return this->isAny || this->time >= otherDate.time;
|
|
}
|
|
|
|
bool Date::operator==(const Date &otherDate) const {
|
|
return this->isAny || this->time == otherDate.time;
|
|
} |