Browse Source

[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 030fb89d6e)
3.0.0/version-upgrade
pinkhello 2 years ago committed by Jiajie Zhong
parent
commit
dca87a4b0c
  1. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
  2. 32
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
  3. 13
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java

1
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;

32
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
*

13
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);
}
}

Loading…
Cancel
Save