提交 dca87a4b 编写于 作者: P pinkhello 提交者: Jiajie Zhong

[Fixed-10833] [Bug] [Quartz] timezone display doesn't match the next_fire_time...

[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 030fb89d)
上级 d2ea5316
......@@ -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;
......
......@@ -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
*
......
......@@ -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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册