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

Fixed panic on debug print of invalid timezones #1013

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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