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


##########
arrow-cast/src/display.rs:
##########
@@ -887,25 +981,113 @@ mod tests {
         );
     }
 
+    fn format_array(array: &dyn Array, fmt: &FormatOptions) -> Vec<String> {
+        let fmt = ArrayFormatter::try_new(array, fmt).unwrap();
+        (0..array.len()).map(|x| fmt.value(x).to_string()).collect()
+    }
+
     #[test]
     fn test_array_value_to_string_duration() {
-        let ns_array = DurationNanosecondArray::from(vec![Some(1), None]);
+        let iso_fmt = FormatOptions::new().with_iso8601_duration_format(true);
+        let h_fmt = FormatOptions::new().with_iso8601_duration_format(false);
+
+        let array = DurationNanosecondArray::from(vec![
+            1,
+            -1,
+            1000,
+            -1000,
+            (45 * 60 * 60 * 24 + 14 * 60 * 60 + 2 * 60 + 34) * 1_000_000_000 + 
123456789,
+            -(45 * 60 * 60 * 24 + 14 * 60 * 60 + 2 * 60 + 34) * 1_000_000_000 
- 123456789,
+        ]);
+        let iso = format_array(&array, &iso_fmt);
+        let non_iso = format_array(&array, &h_fmt);
+
+        assert_eq!(iso[0], "PT0.000000001S");
+        assert_eq!(non_iso[0], "0 days 0 hours 0 mins 0.000000001 secs");
+        assert_eq!(iso[1], "-PT0.000000001S");
+        assert_eq!(non_iso[1], "0 days 0 hours 0 mins -0.000000001 secs");
+        assert_eq!(iso[2], "PT0.000001S");
+        assert_eq!(non_iso[2], "0 days 0 hours 0 mins 0.000001000 secs");

Review Comment:
   I was a little torn on whether to print trailing 0s, we currently do for 
intervals and don't for timestamps. As we are trying to emulate the former, I 
opted to follow that convention



-- 
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