This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 75bca543204 Removed use of SimpleDateFormat in 
IntervalShardingAlgorithm. (#17012)
75bca543204 is described below

commit 75bca5432040a2392b74dfab26fb95620168401c
Author: Ling Hengqian <[email protected]>
AuthorDate: Sat Apr 23 12:33:57 2022 +0800

    Removed use of SimpleDateFormat in IntervalShardingAlgorithm. (#17012)
---
 .../algorithm/sharding/datetime/IntervalShardingAlgorithm.java        | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
index 5dc8db44b07..b6821d93c93 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
@@ -27,8 +27,8 @@ import 
org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingV
 import 
org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
 import 
org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
 
-import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
 import java.time.temporal.ChronoUnit;
@@ -162,7 +162,7 @@ public final class IntervalShardingAlgorithm implements 
StandardShardingAlgorith
             return ((LocalDateTime) endpoint).format(dateTimeFormatter);
         }
         if (endpoint instanceof Date) {
-            return new SimpleDateFormat(getDateTimePattern()).format(endpoint);
+            return ((Date) 
endpoint).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().format(dateTimeFormatter);
         }
         return endpoint.toString();
     }

Reply via email to