[fix](dateformat) Fix hour date format (#19569)

Introduced from #19265.
The hour format should support both "5" and "05".
This commit is contained in:
Mingyu Chen
2023-05-12 13:38:41 +08:00
committed by GitHub
parent 56a6431b55
commit 0477a9f5de
3 changed files with 35 additions and 5 deletions

View File

@ -170,12 +170,16 @@ public class TimeUtils {
return longToTimeStringWithFormat(timeStamp, DATETIME_MS_FORMAT);
}
public static Date getTimeAsDate(String timeString) {
public static Date getHourAsDate(String hour) {
String fullHour = hour;
if (fullHour.length() == 1) {
fullHour = "0" + fullHour;
}
try {
return Date.from(
LocalTime.parse(timeString, TIME_FORMAT).atDate(LocalDate.now()).atZone(TIME_ZONE).toInstant());
LocalTime.parse(fullHour, TIME_FORMAT).atDate(LocalDate.now()).atZone(TIME_ZONE).toInstant());
} catch (DateTimeParseException e) {
LOG.warn("invalid time format: {}", timeString);
LOG.warn("invalid time format: {}", fullHour);
return null;
}
}

View File

@ -88,8 +88,8 @@ public class ConsistencyChecker extends MasterDaemon {
}
private boolean initWorkTime() {
Date startDate = TimeUtils.getTimeAsDate(Config.consistency_check_start_time);
Date endDate = TimeUtils.getTimeAsDate(Config.consistency_check_end_time);
Date startDate = TimeUtils.getHourAsDate(Config.consistency_check_start_time);
Date endDate = TimeUtils.getHourAsDate(Config.consistency_check_end_time);
if (startDate == null || endDate == null) {
return false;