You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/11/29 10:19:23 UTC

[arrow-rs] branch master updated: add test cases for extracing week with timezone (#3218)

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 4926bad4d add test cases for extracing week with timezone (#3218)
4926bad4d is described below

commit 4926bad4d1ae653d01923ebf16d71055eb76da6d
Author: Wei-Ting Kuo <wa...@gmail.com>
AuthorDate: Tue Nov 29 18:19:17 2022 +0800

    add test cases for extracing week with timezone (#3218)
---
 arrow/src/compute/kernels/temporal.rs | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/arrow/src/compute/kernels/temporal.rs b/arrow/src/compute/kernels/temporal.rs
index 9ade79969..cea0a6afc 100644
--- a/arrow/src/compute/kernels/temporal.rs
+++ b/arrow/src/compute/kernels/temporal.rs
@@ -934,6 +934,31 @@ mod tests {
         assert!(matches!(hour(&a), Err(ArrowError::ParseError(_))))
     }
 
+    #[test]
+    fn test_temporal_array_timestamp_week_without_timezone() {
+        // 1970-01-01T00:00:00                     -> 1970-01-01T00:00:00 Thursday (week 1)
+        // 1970-01-01T00:00:00 + 4 days            -> 1970-01-05T00:00:00 Monday   (week 2)
+        // 1970-01-01T00:00:00 + 4 days - 1 second -> 1970-01-04T23:59:59 Sunday   (week 1)
+        let a = TimestampSecondArray::from(vec![0, 86400 * 4, 86400 * 4 - 1]);
+        let b = week(&a).unwrap();
+        assert_eq!(1, b.value(0));
+        assert_eq!(2, b.value(1));
+        assert_eq!(1, b.value(2));
+    }
+
+    #[test]
+    fn test_temporal_array_timestamp_week_with_timezone() {
+        // 1970-01-01T01:00:00+01:00                     -> 1970-01-01T01:00:00+01:00 Thursday (week 1)
+        // 1970-01-01T01:00:00+01:00 + 4 days            -> 1970-01-05T01:00:00+01:00 Monday   (week 2)
+        // 1970-01-01T01:00:00+01:00 + 4 days - 1 second -> 1970-01-05T00:59:59+01:00 Monday   (week 2)
+        let a = TimestampSecondArray::from(vec![0, 86400 * 4, 86400 * 4 - 1])
+            .with_timezone("+01:00".to_string());
+        let b = week(&a).unwrap();
+        assert_eq!(1, b.value(0));
+        assert_eq!(2, b.value(1));
+        assert_eq!(2, b.value(2));
+    }
+
     #[test]
     fn test_hour_minute_second_dictionary_array() {
         let a = TimestampSecondArray::from(vec![