提交 954e57a3 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Limit February 29 date conversion only to years before common transition to Gregorian

上级 883c4c4d
...@@ -502,7 +502,7 @@ public class LocalDateTimeUtils { ...@@ -502,7 +502,7 @@ public class LocalDateTimeUtils {
try { try {
return LOCAL_DATE_OF_YEAR_MONTH_DAY.invoke(null, year, month, day); return LOCAL_DATE_OF_YEAR_MONTH_DAY.invoke(null, year, month, day);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
if (month == 2 && day == 29) { if (year <= 1500 && (year & 3) == 0 && month == 2 && day == 29) {
// If proleptic Gregorian doesn't have such date use the next day // If proleptic Gregorian doesn't have such date use the next day
return LOCAL_DATE_OF_YEAR_MONTH_DAY.invoke(null, year, 3, 1); return LOCAL_DATE_OF_YEAR_MONTH_DAY.invoke(null, year, 3, 1);
} }
......
...@@ -651,12 +651,30 @@ public class TestPreparedStatement extends TestBase { ...@@ -651,12 +651,30 @@ public class TestPreparedStatement extends TestBase {
* Check that date that doesn't exist in proleptic Gregorian calendar can be * Check that date that doesn't exist in proleptic Gregorian calendar can be
* read as a next date. * read as a next date.
*/ */
prep.setString(1, "1500-02-29");
rs = prep.executeQuery();
rs.next();
localDate2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_DATE);
assertEquals(LocalDateTimeUtils.parseLocalDate("1500-03-01"), localDate2);
rs.close();
prep.setString(1, "1400-02-29");
rs = prep.executeQuery();
rs.next();
localDate2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_DATE);
assertEquals(LocalDateTimeUtils.parseLocalDate("1400-03-01"), localDate2);
rs.close();
prep.setString(1, "1300-02-29"); prep.setString(1, "1300-02-29");
rs = prep.executeQuery(); rs = prep.executeQuery();
rs.next(); rs.next();
localDate2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_DATE); localDate2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_DATE);
assertEquals(LocalDateTimeUtils.parseLocalDate("1300-03-01"), localDate2); assertEquals(LocalDateTimeUtils.parseLocalDate("1300-03-01"), localDate2);
rs.close(); rs.close();
prep.setString(1, "-0100-02-29");
rs = prep.executeQuery();
rs.next();
localDate2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_DATE);
assertEquals(LocalDateTimeUtils.parseLocalDate("-0100-03-01"), localDate2);
rs.close();
/* /*
* Check that date that doesn't exist in traditional calendar can be set and * Check that date that doesn't exist in traditional calendar can be set and
* read with LocalDate and can be read with getDate() as a next date. * read with LocalDate and can be read with getDate() as a next date.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论