@@ -155,10 +155,10 @@ fn register_convert_timezone(registry: &mut FunctionRegistry) {
155
155
// Parsing parameters
156
156
let t_tz: Tz = match target_tz. parse ( ) {
157
157
Ok ( tz) => tz,
158
- None => {
158
+ Err ( e ) => {
159
159
return ctx. set_error (
160
160
output. len ( ) ,
161
- "`target_tz` is `None`." . to_string ( ) ,
161
+ format ! ( "cannot parse target `timezone`. {}" , e ) ,
162
162
) ;
163
163
}
164
164
} ;
@@ -174,7 +174,7 @@ fn register_convert_timezone(registry: &mut FunctionRegistry) {
174
174
175
175
let p_src_timestamp: i64 = match Some ( src_timestamp) {
176
176
Ok ( timestamp) => {
177
- timestamp. unwrap ( ) . Utc . timestamp_opt ( src_timestamp, 0 ) . unwrap ( ) ;
177
+ timestamp. Utc . timestamp_opt ( src_timestamp, 0 ) . unwrap ( ) ;
178
178
} ,
179
179
Err ( e) => {
180
180
return ctx. set_error (
@@ -207,41 +207,36 @@ fn register_convert_timezone(registry: &mut FunctionRegistry) {
207
207
) -> Value < TimestampType > {
208
208
vectorize_with_builder_2_arg :: < StringType , TimestampType , TimestampType > (
209
209
|target_tz, src_timestamp, output, ctx| {
210
- // Assume the source timestamp is in UTC
211
- let utc_datetime: DateTime < Utc > = match Some ( src_timestamp) {
212
- Ok ( timestamp) => match Utc . timestamp_opt ( timestamp, 0 ) {
213
- chrono:: LocalResult :: Single ( dt) => dt,
214
- _ => {
215
- return ctx. set_error (
216
- output. len ( ) ,
217
- "cannot parse source `src_timestamp`." . to_string ( ) ,
218
- ) ;
219
- }
220
- } ,
221
- None => {
210
+ // Parse the target timezone
211
+ let t_tz: Tz = match target_tz. parse ( ) {
212
+ Ok ( tz) => tz,
213
+ Err ( e) => {
222
214
return ctx. set_error (
223
215
output. len ( ) ,
224
- "source `src_timestamp` is `None`." . to_string ( ) ,
216
+ format ! ( "cannot parse target `timezone`. {}" , e ) ,
225
217
) ;
226
218
}
227
219
} ;
228
220
229
- // Parse the target timezone
230
- let t_tz: Tz = match target_tz. parse ( ) {
231
- Ok ( tz) => tz,
221
+ // Assume the source timestamp is in UTC
222
+ match Some ( src_timestamp) {
223
+ Ok ( src_timestamp) => {
224
+ let timestamp: i64 = src_timestamp;
225
+ let datetime: DateTime < Utc > = Utc . timestamp_opt ( src_timestamp, 0 ) . unwrap ( ) ;
226
+
227
+ // Convert the UTC time to the specified target timezone
228
+ let target_datetime: DateTime < Tz > = datetime. with_timezone ( & t_tz) ;
229
+ let result_timestamp = target_datetime. timestamp ( ) ;
230
+ // Return the adjusted timestamp as a Unix timestamp in seconds
231
+ output. push ( result_timestamp)
232
+ }
232
233
Err ( e) => {
233
234
return ctx. set_error (
234
235
output. len ( ) ,
235
236
format ! ( "cannot parse target `timezone`. {}" , e) ,
236
237
) ;
237
238
}
238
239
} ;
239
-
240
- // Convert the UTC time to the specified target timezone
241
- let target_datetime: DateTime < Tz > = utc_datetime. with_timezone ( & t_tz) ;
242
- let result_timestamp = target_datetime. timestamp ( ) ;
243
- // Return the adjusted timestamp as a Unix timestamp in seconds
244
- output. push ( result_timestamp)
245
240
} ,
246
241
) ( target_tz, src_timestamp, ctx)
247
242
}
0 commit comments