You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2022/10/20 20:14:29 UTC
[calcite-avatica] 01/02: [CALCITE-1639] TIMESTAMPADD(MONTH, ...) should return last day of month if the day overflows
This is an automated email from the ASF dual-hosted git repository.
jhyde pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git
commit e47b43ee8c818cb2bf18649410cbd6b56f63fe8c
Author: Hongbin Ma <ma...@apache.org>
AuthorDate: Wed Oct 19 13:43:42 2022 -0700
[CALCITE-1639] TIMESTAMPADD(MONTH, ...) should return last day of month if the day overflows
(Copied from Calcite)
---
.../main/java/org/apache/calcite/avatica/util/DateTimeUtils.java | 6 +-----
.../java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java | 8 ++++----
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java b/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
index 6f08114d8..a6bfe0bc1 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
@@ -1039,11 +1039,7 @@ public class DateTimeUtils {
int last = lastDay(y0, m0);
if (d0 > last) {
- d0 = 1;
- if (++m0 > 12) {
- m0 = 1;
- ++y0;
- }
+ d0 = last;
}
return DateTimeUtils.ymdToUnixDate(y0, m0, d0);
}
diff --git a/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java b/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
index b8d1453c4..88066b5a9 100644
--- a/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
+++ b/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
@@ -814,10 +814,10 @@ public class DateTimeUtilsTest {
checkAddMonths(2016, 1, 1, 2017, 2, 1, 13);
checkAddMonths(2016, 1, 1, 2015, 1, 1, -12);
checkAddMonths(2016, 1, 1, 2018, 10, 1, 33);
- checkAddMonths(2016, 1, 31, 2016, 5, 1, 3); // roll up
- checkAddMonths(2016, 4, 30, 2016, 7, 30, 3); // roll up
- checkAddMonths(2016, 1, 31, 2016, 3, 1, 1);
- checkAddMonths(2016, 3, 31, 2016, 3, 1, -1);
+ checkAddMonths(2016, 1, 31, 2016, 4, 30, 3);
+ checkAddMonths(2016, 4, 30, 2016, 7, 30, 3);
+ checkAddMonths(2016, 1, 31, 2016, 2, 29, 1);
+ checkAddMonths(2016, 3, 31, 2016, 2, 29, -1);
checkAddMonths(2016, 3, 31, 2116, 3, 31, 1200);
checkAddMonths(2016, 2, 28, 2116, 2, 28, 1200);
checkAddMonths(2019, 9, 1, 2020, 3, 1, 6);