You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zi...@apache.org on 2022/07/09 14:28:14 UTC
[dolphinscheduler] branch dev updated: [Fixed-10833] [Bug] [Quartz] timezone display doesn't match the next_fire_time in ds 3.0.0-beta1 version (#10865)
This is an automated email from the ASF dual-hosted git repository.
zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 030fb89d6e [Fixed-10833] [Bug] [Quartz] timezone display doesn't match the next_fire_time in ds 3.0.0-beta1 version (#10865)
030fb89d6e is described below
commit 030fb89d6e44875d08ff34d3cd99ee475de13f42
Author: pinkhello <le...@163.com>
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
---
.../api/service/impl/SchedulerServiceImpl.java | 4 ++-
.../api/controller/SchedulerControllerTest.java | 2 +-
.../dolphinscheduler/common/utils/DateUtils.java | 33 ++++++++++++++++++++--
.../common/utils/DateUtilsTest.java | 13 +++++++++
4 files changed, 47 insertions(+), 5 deletions(-)
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 983efa7a11..51ffd6fc1b 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
@@ -72,6 +72,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cronutils.model.Cron;
+
/**
* scheduler service impl
*/
@@ -555,6 +556,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
Cron cron;
ScheduleParam scheduleParam = JSONUtils.parseObject(schedule, ScheduleParam.class);
+ assert scheduleParam != null;
ZoneId zoneId = TimeZone.getTimeZone(scheduleParam.getTimezoneId()).toZoneId();
ZonedDateTime now = ZonedDateTime.now(zoneId);
ZonedDateTime startTime = ZonedDateTime.ofInstant(scheduleParam.getStartTime().toInstant(), zoneId);
@@ -571,7 +573,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
List<ZonedDateTime> selfFireDateList =
CronUtils.getSelfFireDateList(startTime, endTime, cron, Constants.PREVIEW_SCHEDULE_EXECUTE_COUNT);
List<String> previewDateList =
- selfFireDateList.stream().map(DateUtils::dateToString).collect(Collectors.toList());
+ selfFireDateList.stream().map(t -> DateUtils.dateToString(t, zoneId)).collect(Collectors.toList());
result.put(Constants.DATA_LIST, previewDateList);
putMsg(result, Status.SUCCESS);
return result;
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
index 4b6e723a50..7b90330b3d 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
@@ -202,7 +202,7 @@ public class SchedulerControllerTest extends AbstractControllerTest {
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/preview",123)
.header(SESSION_ID, sessionId)
- .param("schedule","{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *'}"))
+ .param("schedule","{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *','timezoneId':'Asia/Shanghai'}"))
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
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 f01f440240..81af098f8b 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
@@ -22,6 +22,8 @@ import org.apache.dolphinscheduler.common.thread.ThreadLocalContext;
import org.apache.commons.lang3.StringUtils;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -31,9 +33,6 @@ import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -164,10 +163,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);
+ }
}