39 int day_in_month[2][13] = {
40 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
41 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
44 Date(
const Date& d) : year_(d.year_), month_(d.month_), day_(d.day_) {}
45 Date(
int y,
int m,
int d) : year_(y), month_(m), day_(d) {}
46 Date(std::string date);
79 inline friend std::ostream&
operator<<(std::ostream& os,
const Date& d);
98 size_t pos = date.find(
"-");
99 year_ = std::stoi(date.substr(0, pos));
100 date.erase(0, pos + 1);
101 pos = date.find(
"-");
102 month_ = std::stoi(date.substr(0, pos));
103 date.erase(0, pos + 1);
104 day_ = std::stoi(date);
105 if (month_ <= 0 || month_ > 12 || day_ > day_in_month[1][month_])
106 throw std::invalid_argument(
"Invalid date specified");
111 os << d.year_ <<
'-' << d.month_ <<
'-' << d.day_;
117 return Date(year_, 12, 31);
147 return Date(year_, month_, day_in_month[1][month_]);
148 return Date(year_, month_, day_in_month[0][month_]);
153 if (month_ == 12 && (day_ + 9) > 31)
167 if (month_ == 12 && day_ == 31)
175 if ((day_ + 7) >= day_in_month[1][month_])
180 if ((day_ + 7) >= day_in_month[0][month_])
189 if (day_ == day_in_month[1][month_])
194 if (day_ == day_in_month[0][month_])
203 return Date(year_, 12, 31);
205 return Date(year_ + 1, 12, 31);
210 if (year_ % 4 == 0 && (year_ % 100 != 0 || year_ % 400 == 0))
217 if (d1.year_ < d2.year_)
219 else if (d1.year_ > d2.year_)
222 if (d1.month_ < d2.month_)
224 else if (d1.month_ > d2.month_)
227 if (d1.day_ <= d2.day_)
242 if (d1.year_ > d2.year_)
244 else if (d1.year_ < d2.year_)
247 if (d1.month_ > d2.month_)
249 else if (d1.month_ < d2.month_)
252 if (d1.day_ >= d2.day_)
267 if (d1.year_ == d2.year_ && d1.month_ == d2.month_ && d1.day_ == d2.day_)
291 if (month_ == 12 && day_ > (31 - (num_days + 1))) {
296 if (day_ > day_in_month[1][month_]) {
297 day_ = day_ - day_in_month[1][month_];
306 if (month_ == 12 && day_ > (31 - num_days)) {
311 if (day_ > day_in_month[0][month_]) {
312 day_ = day_ - day_in_month[0][month_];
331 if (month_ == 12 && day_ > 23) {
336 if (day_ > day_in_month[1][month_]) {
337 day_ = day_ - day_in_month[1][month_];
346 if (month_ == 12 && day_ > 24) {
351 if (day_ > day_in_month[0][month_]) {
352 day_ = day_ - day_in_month[0][month_];
370 if (day_ > day_in_month[1][month_]) {
371 day_ = day_in_month[1][month_];
375 if (day_ > day_in_month[0][month_]) {
376 day_ = day_in_month[0][month_];
415 for (
unsigned i = 0; i < n; i++)
424 for (
unsigned i = 0; i < n; i++)
439 while (start <= *
this) {
454 std::string date = std::to_string(year_) +
"-";
456 date +=
"0" + std::to_string(month_) +
"-";
459 date += std::to_string(month_) +
"-";
462 date +=
"0" + std::to_string(day_);
465 date += std::to_string(day_);
476 Season(
int start,
int end) : start_month_(start), end_month_(end) {}
484 return month >= start_month_ && month <= end_month_;
494 #endif // POPS_DATE_HPP