This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 8ac54d33d Fix parsing timestamps of exactly 32 characters (#3902)
8ac54d33d is described below
commit 8ac54d33d199b464a27cf58b234f0daf7cd453b5
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Wed Mar 22 13:57:37 2023 +0000
Fix parsing timestamps of exactly 32 characters (#3902)
* Fix parsing timestamps of exactly 32 characters
* Format
---
arrow-cast/src/parse.rs | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/arrow-cast/src/parse.rs b/arrow-cast/src/parse.rs
index 710a6a497..4acd2b337 100644
--- a/arrow-cast/src/parse.rs
+++ b/arrow-cast/src/parse.rs
@@ -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;
}
}
@@ -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