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

zhongjiajie pushed a commit to branch 3.0.0-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit dca87a4b0c03cb4532f0014b17f74ac073cbfbf0
Author: pinkhello <[email protected]>
AuthorDate: Sat Jul 9 22:28:08 2022 +0800

    [Fixed-10833] [Bug] [Quartz] timezone display doesn't match the 
next_fire_time in ds 3.0.0-beta1 version (#10865)
    
    * closed [10619]  [Improvement][Master] batch remove TaskInstaceId and 
workflowInstanceId
    
    * fixed # 10833 timezone display error
    
    * checkstyle
    
    (cherry picked from commit 030fb89d6e44875d08ff34d3cd99ee475de13f42)
---
 .../api/service/impl/SchedulerServiceImpl.java     |  1 +
 .../dolphinscheduler/common/utils/DateUtils.java   | 32 ++++++++++++++++++++++
 .../common/utils/DateUtilsTest.java                | 13 +++++++++
 3 files changed, 46 insertions(+)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
index 0909d3e582..c222c4ce2b 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
@@ -571,6 +571,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl 
implements SchedulerSe
         ScheduleParam scheduleParam = JSONUtils.parseObject(schedule, 
ScheduleParam.class);
         Date now = new Date();
 
+        assert scheduleParam != null;
         Date startTime = 
DateUtils.transformTimezoneDate(scheduleParam.getStartTime(), 
scheduleParam.getTimezoneId());
         Date endTime = 
DateUtils.transformTimezoneDate(scheduleParam.getEndTime(), 
scheduleParam.getTimezoneId());
         startTime =  now.after(startTime) ? now : startTime;
diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
index 6ee9ac99d7..392140e555 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
@@ -159,6 +159,38 @@ public final class DateUtils {
         return format(date, YYYY_MM_DD_HH_MM_SS, timezone);
     }
 
+    /**
+     * convert zone date time to yyyy-MM-dd HH:mm:ss format
+     *
+     * @param zonedDateTime zone date time
+     * @return zone date time string
+     */
+    public static String dateToString(ZonedDateTime zonedDateTime) {
+        return YYYY_MM_DD_HH_MM_SS.format(zonedDateTime);
+    }
+
+    /**
+     * convert zone date time to yyyy-MM-dd HH:mm:ss format
+     *
+     * @param zonedDateTime zone date time
+     * @param timezone      time zone
+     * @return zone date time string
+     */
+    public static String dateToString(ZonedDateTime zonedDateTime, String 
timezone) {
+        return dateToString(zonedDateTime, ZoneId.of(timezone));
+    }
+
+    /**
+     * convert zone date time to yyyy-MM-dd HH:mm:ss format
+     *
+     * @param zonedDateTime zone date time
+     * @param zoneId        zone id
+     * @return zone date time string
+     */
+    public static String dateToString(ZonedDateTime zonedDateTime, ZoneId 
zoneId) {
+        return 
DateTimeFormatter.ofPattern(Constants.YYYY_MM_DD_HH_MM_SS).withZone(zoneId).format(zonedDateTime);
+    }
+
     /**
      * convert string to date and time
      *
diff --git 
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
 
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
index 96c4450923..2042fa2d80 100644
--- 
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
+++ 
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
@@ -21,6 +21,8 @@ import 
org.apache.dolphinscheduler.common.thread.ThreadLocalContext;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
 import java.util.Date;
 import java.util.TimeZone;
 
@@ -245,4 +247,15 @@ public class DateUtilsTest {
         Assert.assertEquals(Timer.ONE_HOUR * 8, utcDate.getTime() - 
shanghaiDate.getTime());
 
     }
+
+    @Test
+    public void testDateToString() {
+        ZoneId asiaSh = ZoneId.of("Asia/Shanghai");
+        ZoneId utc = ZoneId.of("UTC");
+        ZonedDateTime asiaShNow = ZonedDateTime.now(asiaSh);
+        ZonedDateTime utcNow = asiaShNow.minusHours(8);
+        String asiaShNowStr = DateUtils.dateToString(utcNow, asiaSh);
+        String utcNowStr = DateUtils.dateToString(asiaShNow, utc);
+        Assert.assertEquals(asiaShNowStr, utcNowStr);
+    }
 }

Reply via email to