Skip to content

Commit 12fb5fa

Browse files
florannTCeason
authored andcommitted
Unit test 7
1 parent 86495ea commit 12fb5fa

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

src/query/functions/src/scalars/datetime.rs

+20-25
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ fn register_convert_timezone(registry: &mut FunctionRegistry) {
155155
// Parsing parameters
156156
let t_tz: Tz = match target_tz.parse() {
157157
Ok(tz) => tz,
158-
None => {
158+
Err(e) => {
159159
return ctx.set_error(
160160
output.len(),
161-
"`target_tz` is `None`.".to_string(),
161+
format!("cannot parse target `timezone`. {}", e),
162162
);
163163
}
164164
};
@@ -174,7 +174,7 @@ fn register_convert_timezone(registry: &mut FunctionRegistry) {
174174

175175
let p_src_timestamp: i64 = match Some(src_timestamp){
176176
Ok(timestamp) => {
177-
timestamp.unwrap().Utc.timestamp_opt(src_timestamp, 0).unwrap();
177+
timestamp.Utc.timestamp_opt(src_timestamp, 0).unwrap();
178178
},
179179
Err(e) => {
180180
return ctx.set_error(
@@ -207,41 +207,36 @@ fn register_convert_timezone(registry: &mut FunctionRegistry) {
207207
) -> Value<TimestampType> {
208208
vectorize_with_builder_2_arg::<StringType, TimestampType, TimestampType>(
209209
|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) => {
222214
return ctx.set_error(
223215
output.len(),
224-
"source `src_timestamp` is `None`.".to_string(),
216+
format!("cannot parse target `timezone`. {}", e),
225217
);
226218
}
227219
};
228220

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+
}
232233
Err(e) => {
233234
return ctx.set_error(
234235
output.len(),
235236
format!("cannot parse target `timezone`. {}", e),
236237
);
237238
}
238239
};
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)
245240
},
246241
)(target_tz, src_timestamp, ctx)
247242
}

0 commit comments

Comments
 (0)