diff --git a/arrow-cast/src/parse.rs b/arrow-cast/src/parse.rs index 710a6a4979c1..4acd2b3376be 100644 --- a/arrow-cast/src/parse.rs +++ b/arrow-cast/src/parse.rs @@ -206,7 +206,7 @@ pub fn string_to_datetime( 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; } } @@ -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