tustvold commented on code in PR #4034:
URL: https://github.com/apache/arrow-rs/pull/4034#discussion_r1160692149


##########
arrow-cast/src/cast.rs:
##########
@@ -8079,24 +8095,45 @@ mod tests {
             let array = Arc::new(valid) as ArrayRef;
             let b = cast_with_options(
                 &array,
-                &DataType::Timestamp(TimeUnit::Nanosecond, Some(tz)),
+                &DataType::Timestamp(TimeUnit::Nanosecond, Some(tz.clone())),
                 &CastOptions { safe: false },
             )
             .unwrap();
 
-            let c = b
-                .as_any()
-                .downcast_ref::<TimestampNanosecondArray>()
-                .unwrap();
-            assert_eq!(1672574706789000000, c.value(0));
-            assert_eq!(1672571106789000000, c.value(1));
-            assert_eq!(1672574706789000000, c.value(2));
-            assert_eq!(1672574706789000000, c.value(3));
-            assert_eq!(1672518906000000000, c.value(4));
-            assert_eq!(1672518906000000000, c.value(5));
-            assert_eq!(1672545906789000000, c.value(6));
-            assert_eq!(1672545906000000000, c.value(7));
-            assert_eq!(1672531200000000000, c.value(8));
+            let tz = tz.as_ref().parse().unwrap();
+
+            let as_tz = |v: i64| {
+                as_datetime_with_timezone::<TimestampNanosecondType>(v, 
tz).unwrap()
+            };
+
+            let as_utc = |v: &i64| as_tz(*v).naive_utc().to_string();
+            let as_local = |v: &i64| as_tz(*v).naive_local().to_string();
+
+            let values = b.as_primitive::<TimestampNanosecondType>().values();
+            let utc_results: Vec<_> = values.iter().map(as_utc).collect();
+            let local_results: Vec<_> = values.iter().map(as_local).collect();
+
+            // Absolute timestamps should be parsed preserving the same UTC 
instant
+            assert_eq!(
+                &utc_results[..6],
+                &[
+                    "2023-01-01 12:05:06.789".to_string(),
+                    "2023-01-01 11:05:06.789".to_string(),
+                    "2023-01-01 12:05:06.789".to_string(),
+                    "2023-01-01 12:05:06.789".to_string(),
+                    "2022-12-31 20:35:06".to_string(),
+                    "2022-12-31 20:35:06".to_string(),
+                ]
+            );
+            // Non-absolute timestamps should be parsed preserving the same 
local instant

Review Comment:
   More background on this can be found in #1936, in particular 
https://github.com/apache/arrow-rs/issues/1936#issuecomment-1253830499



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to