Improve trading window - can specify times as "hh:mm"
This commit is contained in:
@ -1,27 +1,43 @@
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeComparator;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.joda.time.DateTimeComparator;
|
||||
|
||||
|
||||
/**
|
||||
* EPLHelpers contains small helper routines used within epl files.
|
||||
*/
|
||||
public class EPLHelpers {
|
||||
final static Logger log = LoggerFactory.getLogger(EPLHelpers.class);
|
||||
private static DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm");
|
||||
private static DateTimeComparator timeComparator = DateTimeComparator.getTimeOnlyInstance();
|
||||
|
||||
|
||||
/** Return the hour of the day for the given date. */
|
||||
public static int getHour(DateTime date) {
|
||||
return date.getHourOfDay();
|
||||
/**
|
||||
* Return a DateTime object for the time. Should be specified in
|
||||
* 24-hour "hh:mm" format.
|
||||
*/
|
||||
public static DateTime parseTime(String time) {
|
||||
return timeFormatter.parseDateTime(time);
|
||||
}
|
||||
|
||||
/** A simple toString() wrapper for use in epl. */
|
||||
public static String str(Object o) { return o.toString(); }
|
||||
/**
|
||||
* Return true if the time portion of 'now' is between the time
|
||||
* portion of 'start' and 'end'.
|
||||
*/
|
||||
public static boolean inTimeRange(DateTime now, DateTime start, DateTime end) {
|
||||
return laterThan(now, start) && earlierThan(now, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two times and return true if the first is earlier than
|
||||
* the second.
|
||||
*/
|
||||
public static boolean earlierThan(DateTime a, DateTime b) {
|
||||
return DateTimeComparator.getInstance().compare(a, b) < 0;
|
||||
return timeComparator.compare(a, b) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,6 +45,6 @@ public class EPLHelpers {
|
||||
* the second.
|
||||
*/
|
||||
public static boolean laterThan(DateTime a, DateTime b) {
|
||||
return DateTimeComparator.getInstance().compare(a, b) > 0;
|
||||
return timeComparator.compare(a, b) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user