| 349 | } |
| 350 | |
| 351 | DateValue DateValue::AddYears(int64_t years) const { |
| 352 | if (UNLIKELY(!IsValid())) return DateValue(); |
| 353 | |
| 354 | const cctz::civil_day today = EPOCH_DATE + days_since_epoch_; |
| 355 | if (UNLIKELY(years < MIN_YEAR - today.year() || years > MAX_YEAR - today.year())) { |
| 356 | return DateValue(); |
| 357 | } |
| 358 | const int64_t result_year = today.year() + years; |
| 359 | |
| 360 | // Feb 29 in leap years requires special attention. |
| 361 | if (UNLIKELY(today.month() == 2 && today.day() == 29)) { |
| 362 | const cctz::civil_month result_month(result_year, today.month()); |
| 363 | const cctz::civil_day last_day_of_result_month = |
| 364 | cctz::civil_day(result_month + 1) - 1; |
| 365 | return DateValue(result_year, last_day_of_result_month.month(), |
| 366 | last_day_of_result_month.day()); |
| 367 | } |
| 368 | return DateValue(result_year, today.month(), today.day()); |
| 369 | } |
| 370 | |
| 371 | DateValue DateValue::SubtractDays(int64_t days) const { |
| 372 | if (UNLIKELY(!IsValid())) { |