Skip to content

Commit

Permalink
Fix parsing timestamps of exactly 32 characters (#3902)
Browse files Browse the repository at this point in the history
* Fix parsing timestamps of exactly 32 characters

* Format
  • Loading branch information
tustvold authored Mar 22, 2023
1 parent a498a03 commit 8ac54d3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion arrow-cast/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub fn string_to_datetime<T: TimeZone>(

if tz_offset == 32 {
// Decimal overrun
while bytes[tz_offset].is_ascii_digit() && tz_offset < bytes.len() {
while tz_offset < bytes.len() && bytes[tz_offset].is_ascii_digit() {
tz_offset += 1;
}
}
Expand Down Expand Up @@ -1083,6 +1083,22 @@ mod tests {
}
}

#[test]
fn string_to_timestamp_naive() {
let cases = [
"2018-11-13T17:11:10.011375885995",
"2030-12-04T17:11:10.123",
"2030-12-04T17:11:10.1234",
"2030-12-04T17:11:10.123456",
];
for case in cases {
let chrono =
NaiveDateTime::parse_from_str(case, "%Y-%m-%dT%H:%M:%S%.f").unwrap();
let custom = string_to_datetime(&Utc, case).unwrap();
assert_eq!(chrono, custom.naive_utc())
}
}

#[test]
fn string_to_timestamp_invalid() {
// Test parsing invalid formats
Expand Down

0 comments on commit 8ac54d3

Please sign in to comment.