Commit 0199a62c authored by Carlos Aristu's avatar Carlos Aristu
Browse files

[quartz-upgrade] change timestamp and parse methods to receive a date with time

  This makes easier to parse the Next_Fire_Time column which is a DateTime column. The rest of values like "Start Date" (start date + start time) can use the same methods by concatenating date and time"

--HG--
extra : amend_source : 5ccca75231ed1092c263504d6cca1295079c85a6
parent b914d121
......@@ -37,7 +37,8 @@ class LaterTriggerGenerator extends TriggerGenerator {
}
private Date getStartDate(TriggerData data) throws ParseException {
return SchedulerTimeUtils.timestamp(data.startDate, data.startTime);
String dateTime = data.startDate + " " + data.startTime;
return SchedulerTimeUtils.timestamp(dateTime);
}
}
......@@ -56,19 +56,22 @@ abstract class ScheduledTriggerGenerator extends TriggerGenerator {
}
private Date getStartDate(TriggerData data) throws ParseException {
return SchedulerTimeUtils.timestamp(data.startDate, data.startTime);
String dateTime = data.startDate + " " + data.startTime;
return SchedulerTimeUtils.timestamp(dateTime);
}
private Date getFinishDate(TriggerData data) throws ParseException {
return SchedulerTimeUtils.timestamp(data.finishesDate, data.finishesTime);
String dateTime = data.finishesDate + " " + data.finishesTime;
return SchedulerTimeUtils.timestamp(dateTime);
}
private Date getNextFireDate(TriggerData data) throws ParseException {
return SchedulerTimeUtils.timestamp(data.nextFireTime, data.nextFireTime);
return SchedulerTimeUtils.timestamp(data.nextFireTime);
}
protected String getCronTime(TriggerData data) throws ParseException {
LocalDateTime localDateTime = SchedulerTimeUtils.parse(data.startDate, data.startTime);
String dateTime = data.startDate + " " + data.startTime;
LocalDateTime localDateTime = SchedulerTimeUtils.parse(dateTime);
int second = localDateTime.getSecond();
int minute = localDateTime.getMinute();
......
......@@ -41,38 +41,31 @@ class SchedulerTimeUtils {
}
/**
* Utility method to parse a start date string and a start time string into a {@link Date}.
* Utility method to parse a date with time String into a {@link Date}.
*
* @param date
* A date as a String. Expected format: 'dd-MM-yyyy'
*
* @param time
* A time as a String. Expected format: 'HH:mm:ss'
* @param dateTime
* A date with time as a String. Expected format: 'dd-MM-yyyy HH:mm:ss'
*
* @return a {@link Date} with the provided date and time.
*
* @throws ParseException
* if the provided date and time can not be parsed to create the {@link Date} instance.
*/
static Date timestamp(String date, String time) throws ParseException {
LocalDateTime localDateTime = parse(date, time);
static Date timestamp(String dateTime) throws ParseException {
LocalDateTime localDateTime = parse(dateTime);
try {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
} catch (Exception ex) {
log.error("Could not parse date {} {}", date, time, ex);
throw new ParseException("Could not parse date " + date + " " + time, -1);
log.error("Could not parse date {}", dateTime, ex);
throw new ParseException("Could not parse date " + dateTime, -1);
}
}
/**
* Utility method to parse a start date string and a start time string into a
* {@link LocalDateTime}.
*
* @param date
* A date as a String. Expected format: 'dd-MM-yyyy'
* Utility method to parse a date with time String into a {@link LocalDateTime}.
*
* @param time
* A time as a String. Expected format: 'HH:mm:ss'
* @param dateTime
* A date with time as a String. Expected format: 'dd-MM-yyyy HH:mm:ss'
*
* @return a {@link LocalDateTime} with the provided date and time.
*
......@@ -80,12 +73,12 @@ class SchedulerTimeUtils {
* if the provided date and time can not be parsed to create the {@link LocalDateTime}
* instance.
*/
static LocalDateTime parse(String date, String time) throws ParseException {
static LocalDateTime parse(String dateTime) throws ParseException {
try {
return LocalDateTime.parse(date + " " + time, DEFAULT_FORMATTER);
return LocalDateTime.parse(dateTime, DEFAULT_FORMATTER);
} catch (DateTimeParseException ex) {
log.error("Could not parse date {} {}", date, time, ex);
throw new ParseException("Could not parse date " + date + " " + time, -1);
log.error("Could not parse date {}", dateTime, ex);
throw new ParseException("Could not parse date " + dateTime, -1);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment