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


##########
arrow-buffer/src/interval.rs:
##########
@@ -0,0 +1,424 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::arith::derive_arith;
+use std::ops::Neg;
+
+/// Value of an IntervalMonthDayNano array
+#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
+#[repr(C)]
+pub struct IntervalMonthDayNano {
+    pub months: i32,
+    pub days: i32,
+    pub nanoseconds: i64,
+}
+
+impl IntervalMonthDayNano {
+    /// The additive identity i.e. `0`.
+    pub const ZERO: Self = Self::new(0, 0, 0);
+
+    /// The multiplicative identity, i.e. `1`.
+    pub const ONE: Self = Self::new(1, 1, 1);
+
+    /// The multiplicative inverse, i.e. `-1`.
+    pub const MINUS_ONE: Self = Self::new(-1, -1, -1);
+
+    /// The maximum value that can be represented
+    pub const MAX: Self = Self::new(i32::MAX, i32::MAX, i64::MAX);
+
+    /// The minimum value that can be represented
+    pub const MIN: Self = Self::new(i32::MIN, i32::MIN, i64::MIN);
+
+    /// Create a new [`IntervalMonthDayNano`]
+    #[inline]
+    pub const fn new(months: i32, days: i32, nanoseconds: i64) -> Self {
+        Self {
+            months,
+            days,
+            nanoseconds,
+        }
+    }
+
+    /// Computes the absolute value
+    #[inline]
+    pub fn wrapping_abs(self) -> Self {
+        Self {
+            months: self.months.wrapping_abs(),
+            days: self.days.wrapping_abs(),
+            nanoseconds: self.nanoseconds.wrapping_abs(),
+        }
+    }
+
+    /// Computes the absolute value
+    #[inline]
+    pub fn checked_abs(self) -> Option<Self> {
+        Some(Self {
+            months: self.months.checked_abs()?,
+            days: self.days.checked_abs()?,
+            nanoseconds: self.nanoseconds.checked_abs()?,
+        })
+    }
+
+    /// Negates the value
+    #[inline]
+    pub fn wrapping_neg(self) -> Self {
+        Self {
+            months: self.months.wrapping_neg(),
+            days: self.days.wrapping_neg(),
+            nanoseconds: self.nanoseconds.wrapping_neg(),
+        }
+    }
+
+    /// Negates the value
+    #[inline]
+    pub fn checked_neg(self) -> Option<Self> {
+        Some(Self {
+            months: self.months.checked_neg()?,
+            days: self.days.checked_neg()?,
+            nanoseconds: self.nanoseconds.checked_neg()?,
+        })
+    }
+
+    /// Performs wrapping addition
+    #[inline]
+    pub fn wrapping_add(self, other: Self) -> Self {
+        Self {
+            months: self.months.wrapping_add(other.months),
+            days: self.days.wrapping_add(other.days),
+            nanoseconds: self.nanoseconds.wrapping_add(other.nanoseconds),
+        }
+    }
+
+    /// Performs checked addition
+    #[inline]
+    pub fn checked_add(self, other: Self) -> Option<Self> {
+        Some(Self {
+            months: self.months.checked_add(other.months)?,
+            days: self.days.checked_add(other.days)?,
+            nanoseconds: self.nanoseconds.checked_add(other.nanoseconds)?,
+        })
+    }

Review Comment:
   Days don't necessarily have 24 hours, e.g. DST. The components of an 
interval are separate solely because it is incorrect to do what you describe



-- 
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-unsubscr...@arrow.apache.org

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

Reply via email to