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 c7cf79276 Add timezone accessor for Timestamp*Array (#3666)
c7cf79276 is described below
commit c7cf7927621a54ed56a4006f4606e4313e0923f0
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Mon Feb 6 18:46:07 2023 +0000
Add timezone accessor for Timestamp*Array (#3666)
---
arrow-array/src/array/primitive_array.rs | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/arrow-array/src/array/primitive_array.rs
b/arrow-array/src/array/primitive_array.rs
index dfe076306..6902f1364 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -1019,6 +1019,14 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
Self::from(data).with_timezone_opt(timezone)
}
+ /// Returns the timezone of this array if any
+ pub fn timezone(&self) -> Option<&str> {
+ match self.data_type() {
+ DataType::Timestamp(_, tz) => tz.as_deref(),
+ _ => unreachable!(),
+ }
+ }
+
/// Construct a timestamp array with new timezone
pub fn with_timezone(&self, timezone: impl Into<String>) -> Self {
self.with_timezone_opt(Some(timezone.into()))
@@ -2214,4 +2222,13 @@ mod tests {
let array = IntervalDayTimeArray::from(vec![1, 2, 3]);
let _ = IntervalMonthDayNanoArray::from(array.into_data());
}
+
+ #[test]
+ fn test_timezone() {
+ let array = TimestampNanosecondArray::from_iter_values([1, 2]);
+ assert_eq!(array.timezone(), None);
+
+ let array = array.with_timezone("+02:00");
+ assert_eq!(array.timezone(), Some("+02:00"));
+ }
}