diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java index abdf13b8b7a05..e6e1c1bfbb6f6 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java @@ -332,6 +332,9 @@ private String getDateTimeText(final Comparable endpoint) { if (endpoint instanceof TemporalAccessor) { return dateTimeFormatter.format((TemporalAccessor) endpoint); } + if (endpoint instanceof java.sql.Date) { + return dateTimeFormatter.format(((java.sql.Date) endpoint).toLocalDate().atStartOfDay(ZoneId.systemDefault())); + } if (endpoint instanceof Date) { return dateTimeFormatter.format(((Date) endpoint).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java index 5b51ac59b5808..bfdc8d4272c83 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java @@ -27,6 +27,7 @@ import org.junit.Before; import org.junit.Test; +import java.sql.Date; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -448,4 +449,13 @@ public void assertIntegerInJDBCType() { new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed("04", "10"))); assertThat(actualAsMonthString.size(), is(4)); } + + @Test + public void assertDateInSqlDate() { + Collection actualAsLocalDate = shardingAlgorithmByJDBCDate.doSharding(availableTablesForJDBCDateDataSources, + new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, + Range.closed(new Date(LocalDate.of(2021, 6, 15).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli()), + new Date(LocalDate.of(2021, 7, 31).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli())))); + assertThat(actualAsLocalDate.size(), is(24)); + } }