更改文件夹名。
This commit is contained in:
73
FinalProject/Date.cpp
Normal file
73
FinalProject/Date.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user