| 117 | } |
| 118 | |
| 119 | TimestampVal TimestampFunctions::FromUtc(FunctionContext* context, |
| 120 | const TimestampVal& ts_val, const StringVal& tz_string_val) { |
| 121 | if (ts_val.is_null || tz_string_val.is_null) return TimestampVal::null(); |
| 122 | const TimestampValue ts_value = TimestampValue::FromTimestampVal(ts_val); |
| 123 | if (UNLIKELY(!ts_value.HasDateAndTime())) return TimestampVal::null(); |
| 124 | |
| 125 | const StringValue& tz_string_value = StringValue::FromStringVal(tz_string_val); |
| 126 | const Timezone* timezone = GetTimezone(context, tz_string_value); |
| 127 | if (UNLIKELY(timezone == nullptr)) return ts_val; |
| 128 | |
| 129 | TimestampValue ts_value_ret = ts_value; |
| 130 | ts_value_ret.UtcToLocal(*timezone); |
| 131 | if (UNLIKELY(!ts_value_ret.HasDateAndTime())) { |
| 132 | const string msg = Substitute( |
| 133 | "Timestamp '$0' did not convert to a valid local time in timezone '$1'", |
| 134 | ts_value.ToString(), tz_string_value.DebugString()); |
| 135 | context->AddWarning(msg.c_str()); |
| 136 | return TimestampVal::null(); |
| 137 | } |
| 138 | |
| 139 | TimestampVal ts_val_ret; |
| 140 | ts_value_ret.ToTimestampVal(&ts_val_ret); |
| 141 | return ts_val_ret; |
| 142 | } |
| 143 | |
| 144 | TimestampVal TimestampFunctions::ToUtc(FunctionContext* context, |
| 145 | const TimestampVal& ts_val, const StringVal& tz_string_val) { |
nothing calls this directly
no test coverage detected