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

mbrobbel pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 07b2503ec4 Impl `Display` for `Tz` (#8275)
07b2503ec4 is described below

commit 07b2503ec4b0f77ca834a9ef9b2f6696a609736e
Author: Kyle Barron <k...@developmentseed.org>
AuthorDate: Fri Sep 5 08:37:30 2025 -0400

    Impl `Display` for `Tz` (#8275)
    
    # Which issue does this PR close?
    
    
    - Closes #7173.
    
    # Rationale for this change
    
    Ability to round-trip timezone information.
    
    # What changes are included in this PR?
    
    Impl `Display` for `Tz`
    
    # Are these changes tested?
    
    A simple test that strings round trip.
    
    # Are there any user-facing changes?
    
    New API
---
 arrow-array/src/timezone.rs | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arrow-array/src/timezone.rs b/arrow-array/src/timezone.rs
index b4df77deb4..bcf5821521 100644
--- a/arrow-array/src/timezone.rs
+++ b/arrow-array/src/timezone.rs
@@ -53,6 +53,7 @@ mod private {
     use super::*;
     use chrono::offset::TimeZone;
     use chrono::{LocalResult, NaiveDate, NaiveDateTime, Offset};
+    use std::fmt::Display;
     use std::str::FromStr;
 
     /// An [`Offset`] for [`Tz`]
@@ -97,6 +98,15 @@ mod private {
         }
     }
 
+    impl Display for Tz {
+        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+            match self.0 {
+                TzInner::Timezone(tz) => tz.fmt(f),
+                TzInner::Offset(offset) => offset.fmt(f),
+            }
+        }
+    }
+
     macro_rules! tz {
         ($s:ident, $tz:ident, $b:block) => {
             match $s.0 {
@@ -228,6 +238,15 @@ mod private {
                 sydney_offset_with_dst
             );
         }
+
+        #[test]
+        fn test_timezone_display() {
+            let test_cases = ["UTC", "America/Los_Angeles", "-08:00", 
"+05:30"];
+            for &case in &test_cases {
+                let tz: Tz = case.parse().unwrap();
+                assert_eq!(tz.to_string(), case);
+            }
+        }
     }
 }
 

Reply via email to