Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Fixed panic on debug print of invalid tz (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed May 27, 2022
1 parent 2ed756a commit b5bbe9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/array/primitive/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,26 @@ pub fn get_write_value<'a, T: NativeType, F: Write>(
}
#[cfg(feature = "chrono-tz")]
Err(_) => {
let timezone = temporal_conversions::parse_offset_tz(tz).unwrap();
dyn_primitive!(array, i64, |time| {
temporal_conversions::timestamp_to_datetime(time, *time_unit, &timezone)
})
let timezone = temporal_conversions::parse_offset_tz(tz);
match timezone {
Ok(timezone) => dyn_primitive!(array, i64, |time| {
temporal_conversions::timestamp_to_datetime(
time, *time_unit, &timezone,
)
}),
Err(_) => {
let tz = tz.clone();
Box::new(move |f, index| {
write!(f, "{} ({})", array.value(index), tz)
})
}
}
}
#[cfg(not(feature = "chrono-tz"))]
_ => panic!(
"Invalid Offset format (must be [-]00:00) or chrono-tz feature not active"
),
_ => {
let tz = tz.clone();
Box::new(move |f, index| write!(f, "{} ({})", array.value(index), tz))
}
}
} else {
dyn_primitive!(array, i64, |time| {
Expand Down
12 changes: 12 additions & 0 deletions tests/it/array/primitive/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ fn debug_timestamp_tz_ns() {
);
}

#[test]
fn debug_timestamp_tz_not_parsable() {
let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Timestamp(
TimeUnit::Nanosecond,
Some("aa".to_string()),
));
assert_eq!(
format!("{:?}", array),
"Timestamp(Nanosecond, Some(\"aa\"))[1 (aa), None, 2 (aa)]"
);
}

#[cfg(feature = "chrono-tz")]
#[test]
fn debug_timestamp_tz1_ns() {
Expand Down

0 comments on commit b5bbe9f

Please sign in to comment.