[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
This commit is contained in:
parent
73f4846c49
commit
030fb89d6e
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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…
Reference in New Issue