This is an automated email from the ASF dual-hosted git repository.

alamb 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 499301c  fix: nanosecond timestamp scaling during string conversion 
(#780) (#781)
499301c is described below

commit 499301c7ff89b3dcf675bd067442077ff574eba7
Author: Ilya Biryukov <[email protected]>
AuthorDate: Fri Sep 17 19:06:35 2021 +0300

    fix: nanosecond timestamp scaling during string conversion (#780) (#781)
    
    Some datetime formats passed to `string_to_timestamp_nanos` were parsing
    milliseconds as nanoseconds.
    
    E.g. `1970-01-01 00:00:00.123` would parse as `123` nanoseconds instead
    of milliseconds.
---
 arrow/src/compute/kernels/cast_utils.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arrow/src/compute/kernels/cast_utils.rs 
b/arrow/src/compute/kernels/cast_utils.rs
index 0088e9f..8c1b669 100644
--- a/arrow/src/compute/kernels/cast_utils.rs
+++ b/arrow/src/compute/kernels/cast_utils.rs
@@ -95,7 +95,7 @@ pub fn string_to_timestamp_nanos(s: &str) -> Result<i64> {
 
     // without a timezone specifier as a local time, using T as a separator
     // Example: 2020-09-08T13:42:29.190855
-    if let Ok(ts) = NaiveDateTime::parse_from_str(s, "%Y-%m-%dT%H:%M:%S.%f") {
+    if let Ok(ts) = NaiveDateTime::parse_from_str(s, "%Y-%m-%dT%H:%M:%S%.f") {
         return naive_datetime_to_timestamp(s, ts);
     }
 
@@ -108,7 +108,7 @@ pub fn string_to_timestamp_nanos(s: &str) -> Result<i64> {
 
     // without a timezone specifier as a local time, using ' ' as a separator
     // Example: 2020-09-08 13:42:29.190855
-    if let Ok(ts) = NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S.%f") {
+    if let Ok(ts) = NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.f") {
         return naive_datetime_to_timestamp(s, ts);
     }
 
@@ -227,7 +227,7 @@ mod tests {
         // somewhat suceptable to bugs in the use of chrono
         let naive_datetime = NaiveDateTime::new(
             NaiveDate::from_ymd(2020, 9, 8),
-            NaiveTime::from_hms_nano(13, 42, 29, 190855),
+            NaiveTime::from_hms_nano(13, 42, 29, 190855000),
         );
 
         // Ensure both T and ' ' variants work

Reply via email to