You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/24 17:28:15 UTC

[GitHub] [arrow-rs] psvri commented on a diff in pull request #3183: Duration display

psvri commented on code in PR #3183:
URL: https://github.com/apache/arrow-rs/pull/3183#discussion_r1031733918


##########
arrow-cast/src/display.rs:
##########
@@ -549,3 +553,34 @@ pub fn lexical_to_string<N: lexical_core::ToLexical>(n: N) -> String {
         String::from_utf8_unchecked(buf)
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn test_array_value_to_string_duration() {
+        let ns_array =
+            Arc::new(DurationNanosecondArray::from(vec![Some(1), None])) as ArrayRef;
+        assert_eq!(
+            array_value_to_string(&ns_array, 0).unwrap(),
+            "PT0.000000001S"
+        );
+        assert_eq!(array_value_to_string(&ns_array, 1).unwrap(), "");
+
+        let us_array =
+            Arc::new(DurationMicrosecondArray::from(vec![Some(1), None])) as ArrayRef;
+        assert_eq!(array_value_to_string(&us_array, 0).unwrap(), "PT0.000001S");

Review Comment:
   `chrono::Duration.to_string()` is displayed like that. We cannot use std::time::Duration here because arrow array duration can be negative. 
   
   IMHO is am very tempted to replace `P` and `T` chars and make the `S` as small to improve readability.
   
   



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org