| 574 | } |
| 575 | |
| 576 | DoubleVal TimestampFunctions::MonthsBetween(FunctionContext* context, |
| 577 | const TimestampVal& ts1, const TimestampVal& ts2) { |
| 578 | if (ts1.is_null || ts2.is_null) return DoubleVal::null(); |
| 579 | const TimestampValue& ts_value1 = TimestampValue::FromTimestampVal(ts1); |
| 580 | const TimestampValue& ts_value2 = TimestampValue::FromTimestampVal(ts2); |
| 581 | if (!ts_value1.HasDate() || !ts_value2.HasDate()) return DoubleVal::null(); |
| 582 | IntVal year1 = Year(context, ts1); |
| 583 | IntVal year2 = Year(context, ts2); |
| 584 | IntVal month1 = Month(context, ts1); |
| 585 | IntVal month2 = Month(context, ts2); |
| 586 | IntVal day1 = DayOfMonth(context, ts1); |
| 587 | IntVal day2 = DayOfMonth(context, ts2); |
| 588 | int days_diff = 0; |
| 589 | // If both timestamps are last days of different months they don't contribute |
| 590 | // a fractional value to the number of months, therefore there is no need to |
| 591 | // calculate difference in their days. |
| 592 | if (!(day1.val == GetLastDayOfMonth(month1.val, year1.val) && |
| 593 | day2.val == GetLastDayOfMonth(month2.val, year2.val))) { |
| 594 | days_diff = day1.val - day2.val; |
| 595 | } |
| 596 | double months_between = (year1.val - year2.val) * 12 + |
| 597 | month1.val - month2.val + (static_cast<double>(days_diff) / 31.0); |
| 598 | return DoubleVal(months_between); |
| 599 | } |
| 600 | |
| 601 | TimestampVal TimestampFunctions::NextDay(FunctionContext* context, |
| 602 | const TimestampVal& date, const StringVal& weekday) { |
nothing calls this directly
no test coverage detected