MCPcopy Create free account
hub / github.com/apache/impala / AddYears

Method AddYears

be/src/runtime/date-value.cc:351–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351DateValue 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
371DateValue DateValue::SubtractDays(int64_t days) const {
372 if (UNLIKELY(!IsValid())) {

Callers 2

AddSubYearsMethod · 0.80
TESTFunction · 0.80

Calls 4

yearMethod · 0.80
monthMethod · 0.80
dayMethod · 0.80
DateValueClass · 0.70

Tested by 1

TESTFunction · 0.64