| 246 | |
| 247 | template <bool is_add, typename AnyIntVal> |
| 248 | DateVal DateFunctions::AddSubWeeks(FunctionContext* context, const DateVal& d_val, |
| 249 | const AnyIntVal& num_weeks) { |
| 250 | if (d_val.is_null || num_weeks.is_null) return DateVal::null(); |
| 251 | |
| 252 | // Sanity check: make sure that the number of weeks converted to days fits into 64-bits. |
| 253 | int64_t weeks = is_add ? num_weeks.val : -num_weeks.val; |
| 254 | if (weeks > numeric_limits<int64_t>::max() / 7 |
| 255 | || weeks < numeric_limits<int64_t>::min() / 7) { |
| 256 | return DateVal::null(); |
| 257 | } |
| 258 | |
| 259 | const DateValue dv = DateValue::FromDateVal(d_val).AddDays(weeks * 7); |
| 260 | return dv.ToDateVal(); |
| 261 | } |
| 262 | |
| 263 | // Explicit template instantiation is required for proper linking. These functions |
| 264 | // are only indirectly called via a function pointer provided by the opcode registry |