cht42 commented on code in PR #9144:
URL: https://github.com/apache/arrow-rs/pull/9144#discussion_r2700807112


##########
arrow-array/src/delta.rs:
##########
@@ -91,195 +90,175 @@ pub(crate) fn sub_days_datetime<Tz: TimeZone>(dt: 
DateTime<Tz>, days: i32) -> Op
 #[cfg(test)]
 mod tests {
 
-    use chrono::naive::{NaiveDate, NaiveDateTime, NaiveTime};
+    use chrono::naive::NaiveDate;
 
     use super::*;
 
     #[test]
-    fn test_shift_months() {
+    fn test_add_monts_months() {
         let base = NaiveDate::from_ymd_opt(2020, 1, 31).unwrap();
 
         assert_eq!(
-            shift_months(base, 0),
-            NaiveDate::from_ymd_opt(2020, 1, 31).unwrap()
+            add_months_date(base, 0),
+            NaiveDate::from_ymd_opt(2020, 1, 31)
         );
         assert_eq!(
-            shift_months(base, 1),
-            NaiveDate::from_ymd_opt(2020, 2, 29).unwrap()
+            add_months_date(base, 1),
+            NaiveDate::from_ymd_opt(2020, 2, 29)
         );
         assert_eq!(
-            shift_months(base, 2),
-            NaiveDate::from_ymd_opt(2020, 3, 31).unwrap()
+            add_months_date(base, 2),
+            NaiveDate::from_ymd_opt(2020, 3, 31)
         );
         assert_eq!(
-            shift_months(base, 3),
-            NaiveDate::from_ymd_opt(2020, 4, 30).unwrap()
+            add_months_date(base, 3),
+            NaiveDate::from_ymd_opt(2020, 4, 30)
         );
         assert_eq!(
-            shift_months(base, 4),
-            NaiveDate::from_ymd_opt(2020, 5, 31).unwrap()
+            add_months_date(base, 4),
+            NaiveDate::from_ymd_opt(2020, 5, 31)
         );
         assert_eq!(
-            shift_months(base, 5),
-            NaiveDate::from_ymd_opt(2020, 6, 30).unwrap()
+            add_months_date(base, 5),
+            NaiveDate::from_ymd_opt(2020, 6, 30)
         );
         assert_eq!(
-            shift_months(base, 6),
-            NaiveDate::from_ymd_opt(2020, 7, 31).unwrap()
+            add_months_date(base, 6),
+            NaiveDate::from_ymd_opt(2020, 7, 31)
         );
         assert_eq!(
-            shift_months(base, 7),
-            NaiveDate::from_ymd_opt(2020, 8, 31).unwrap()
+            add_months_date(base, 7),
+            NaiveDate::from_ymd_opt(2020, 8, 31)
         );
         assert_eq!(
-            shift_months(base, 8),
-            NaiveDate::from_ymd_opt(2020, 9, 30).unwrap()
+            add_months_date(base, 8),
+            NaiveDate::from_ymd_opt(2020, 9, 30)
         );
         assert_eq!(
-            shift_months(base, 9),
-            NaiveDate::from_ymd_opt(2020, 10, 31).unwrap()
+            add_months_date(base, 9),
+            NaiveDate::from_ymd_opt(2020, 10, 31)
         );
         assert_eq!(
-            shift_months(base, 10),
-            NaiveDate::from_ymd_opt(2020, 11, 30).unwrap()
+            add_months_date(base, 10),
+            NaiveDate::from_ymd_opt(2020, 11, 30)
         );
         assert_eq!(
-            shift_months(base, 11),
-            NaiveDate::from_ymd_opt(2020, 12, 31).unwrap()
+            add_months_date(base, 11),
+            NaiveDate::from_ymd_opt(2020, 12, 31)
         );
         assert_eq!(
-            shift_months(base, 12),
-            NaiveDate::from_ymd_opt(2021, 1, 31).unwrap()
+            add_months_date(base, 12),
+            NaiveDate::from_ymd_opt(2021, 1, 31)
         );
         assert_eq!(
-            shift_months(base, 13),
-            NaiveDate::from_ymd_opt(2021, 2, 28).unwrap()
+            add_months_date(base, 13),
+            NaiveDate::from_ymd_opt(2021, 2, 28)
         );
 
         assert_eq!(
-            shift_months(base, -1),
-            NaiveDate::from_ymd_opt(2019, 12, 31).unwrap()
+            add_months_date(base, -1),
+            NaiveDate::from_ymd_opt(2019, 12, 31)
         );
         assert_eq!(
-            shift_months(base, -2),
-            NaiveDate::from_ymd_opt(2019, 11, 30).unwrap()
+            add_months_date(base, -2),
+            NaiveDate::from_ymd_opt(2019, 11, 30)
         );
         assert_eq!(
-            shift_months(base, -3),
-            NaiveDate::from_ymd_opt(2019, 10, 31).unwrap()
+            add_months_date(base, -3),
+            NaiveDate::from_ymd_opt(2019, 10, 31)
         );
         assert_eq!(
-            shift_months(base, -4),
-            NaiveDate::from_ymd_opt(2019, 9, 30).unwrap()
+            add_months_date(base, -4),
+            NaiveDate::from_ymd_opt(2019, 9, 30)
         );
         assert_eq!(
-            shift_months(base, -5),
-            NaiveDate::from_ymd_opt(2019, 8, 31).unwrap()
+            add_months_date(base, -5),
+            NaiveDate::from_ymd_opt(2019, 8, 31)
         );
         assert_eq!(
-            shift_months(base, -6),
-            NaiveDate::from_ymd_opt(2019, 7, 31).unwrap()
+            add_months_date(base, -6),
+            NaiveDate::from_ymd_opt(2019, 7, 31)
         );
         assert_eq!(
-            shift_months(base, -7),
-            NaiveDate::from_ymd_opt(2019, 6, 30).unwrap()
+            add_months_date(base, -7),
+            NaiveDate::from_ymd_opt(2019, 6, 30)
         );
         assert_eq!(
-            shift_months(base, -8),
-            NaiveDate::from_ymd_opt(2019, 5, 31).unwrap()
+            add_months_date(base, -8),
+            NaiveDate::from_ymd_opt(2019, 5, 31)
         );
         assert_eq!(
-            shift_months(base, -9),
-            NaiveDate::from_ymd_opt(2019, 4, 30).unwrap()
+            add_months_date(base, -9),
+            NaiveDate::from_ymd_opt(2019, 4, 30)
         );
         assert_eq!(
-            shift_months(base, -10),
-            NaiveDate::from_ymd_opt(2019, 3, 31).unwrap()
+            add_months_date(base, -10),
+            NaiveDate::from_ymd_opt(2019, 3, 31)
         );
         assert_eq!(
-            shift_months(base, -11),
-            NaiveDate::from_ymd_opt(2019, 2, 28).unwrap()
+            add_months_date(base, -11),
+            NaiveDate::from_ymd_opt(2019, 2, 28)
         );
         assert_eq!(
-            shift_months(base, -12),
-            NaiveDate::from_ymd_opt(2019, 1, 31).unwrap()
+            add_months_date(base, -12),
+            NaiveDate::from_ymd_opt(2019, 1, 31)
         );
         assert_eq!(
-            shift_months(base, -13),
-            NaiveDate::from_ymd_opt(2018, 12, 31).unwrap()
+            add_months_date(base, -13),
+            NaiveDate::from_ymd_opt(2018, 12, 31)
         );
 
         assert_eq!(
-            shift_months(base, 1265),
-            NaiveDate::from_ymd_opt(2125, 6, 30).unwrap()
+            add_months_date(base, 1265),
+            NaiveDate::from_ymd_opt(2125, 6, 30)
         );
+
+        // overflow handling
+        assert_eq!(add_months_date(base, i32::MAX), None);
+        assert_eq!(add_months_date(base, i32::MIN), None);
     }
 
     #[test]
-    fn test_shift_months_with_overflow() {
+    fn test_add_months_date_with_overflow() {
         let base = NaiveDate::from_ymd_opt(2020, 12, 31).unwrap();
 
-        assert_eq!(shift_months(base, 0), base);
+        assert_eq!(add_months_date(base, 0), Some(base));
         assert_eq!(
-            shift_months(base, 1),
-            NaiveDate::from_ymd_opt(2021, 1, 31).unwrap()
+            add_months_date(base, 1),
+            NaiveDate::from_ymd_opt(2021, 1, 31)
         );
         assert_eq!(
-            shift_months(base, 2),
-            NaiveDate::from_ymd_opt(2021, 2, 28).unwrap()
+            add_months_date(base, 2),
+            NaiveDate::from_ymd_opt(2021, 2, 28)
         );
         assert_eq!(
-            shift_months(base, 12),
-            NaiveDate::from_ymd_opt(2021, 12, 31).unwrap()
+            add_months_date(base, 12),
+            NaiveDate::from_ymd_opt(2021, 12, 31)
         );
         assert_eq!(
-            shift_months(base, 18),
-            NaiveDate::from_ymd_opt(2022, 6, 30).unwrap()
+            add_months_date(base, 18),
+            NaiveDate::from_ymd_opt(2022, 6, 30)
         );
 
         assert_eq!(
-            shift_months(base, -1),
-            NaiveDate::from_ymd_opt(2020, 11, 30).unwrap()
-        );
-        assert_eq!(
-            shift_months(base, -2),
-            NaiveDate::from_ymd_opt(2020, 10, 31).unwrap()
-        );
-        assert_eq!(
-            shift_months(base, -10),
-            NaiveDate::from_ymd_opt(2020, 2, 29).unwrap()
+            add_months_date(base, -1),
+            NaiveDate::from_ymd_opt(2020, 11, 30)
         );
         assert_eq!(
-            shift_months(base, -12),
-            NaiveDate::from_ymd_opt(2019, 12, 31).unwrap()
+            add_months_date(base, -2),
+            NaiveDate::from_ymd_opt(2020, 10, 31)
         );
         assert_eq!(
-            shift_months(base, -18),
-            NaiveDate::from_ymd_opt(2019, 6, 30).unwrap()
-        );
-    }
-
-    #[test]
-    fn test_shift_months_datetime() {

Review Comment:
   we don't need those datetime tests anymore, `add_months_date` only accepts 
`NaiveDate`



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