Package org.planit.time
Class TimePeriod
- java.lang.Object
-
- org.planit.time.TimePeriod
-
- All Implemented Interfaces:
Comparable<TimePeriod>
public class TimePeriod extends Object implements Comparable<TimePeriod>
Represents a time period within the day. Used to determine the duration and start time of trips for example We internally adopt seconds as the unit- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description TimePeriod(IdGroupingToken groupId, Object externalId, long startTimeSeconds, long durationSeconds)ConstructorTimePeriod(IdGroupingToken groupId, Object externalId, String description, long startTimeSeconds, long durationSeconds)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(TimePeriod o)Compare this object with another TimePeriod object Comparison is based on start time and durationstatic longconvertHoursToSeconds(double hoursFromMidnight)Convert hours to (whole) secondsstatic longconvertHoursToSeconds(String fourDigitHour)Convert duration to seconds given start time using the 24-hour clockstatic floatconvertSecondsToHours(int secondsFromMidnight)Convert seconds to 24h format from midnight to secondsStringgetDescription()Return the descriptionlonggetDurationSeconds()Return the duration in secondsObjectgetExternalId()Return the external id of this time periodlonggetId()Return the id of this time periodlonggetStartTimeSeconds()Return the start timebooleanhasExternalId()Returns whether this time period has its external id setStringtoString()Output this object as a String
-
-
-
Constructor Detail
-
TimePeriod
public TimePeriod(IdGroupingToken groupId, Object externalId, long startTimeSeconds, long durationSeconds) throws PlanItException
Constructor- Parameters:
groupId- contiguous id generation within this group for instances of this classexternalId- externalId of this time periodstartTimeSeconds- start time in seconds from midnightdurationSeconds- duration in seconds- Throws:
PlanItException- thrown if error
-
TimePeriod
public TimePeriod(IdGroupingToken groupId, Object externalId, String description, long startTimeSeconds, long durationSeconds) throws PlanItException
Constructor- Parameters:
groupId- contiguous id generation within this group for instances of this classexternalId- externalId of this time perioddescription- description of this time periodstartTimeSeconds- start time of this time perioddurationSeconds- duration of this time period- Throws:
PlanItException- thrown if error
-
-
Method Detail
-
convertHoursToSeconds
public static long convertHoursToSeconds(String fourDigitHour) throws PlanItException
Convert duration to seconds given start time using the 24-hour clock- Parameters:
fourDigitHour- start time in 24-hour clock format (four digits exactly)- Returns:
- duration in seconds
- Throws:
PlanItException- thrown if the input time is not in the correct format
-
convertHoursToSeconds
public static long convertHoursToSeconds(double hoursFromMidnight)
Convert hours to (whole) seconds- Parameters:
hoursFromMidnight- the hours from midnight- Returns:
- secondsFromMidnight the seconds from midnight
-
convertSecondsToHours
public static float convertSecondsToHours(int secondsFromMidnight)
Convert seconds to 24h format from midnight to seconds- Parameters:
secondsFromMidnight- seconds from midnight- Returns:
- hours from midnight
-
getStartTimeSeconds
public long getStartTimeSeconds()
Return the start time- Returns:
- start time
-
getDurationSeconds
public long getDurationSeconds()
Return the duration in seconds- Returns:
- duration
-
getDescription
public String getDescription()
Return the description- Returns:
- description of this TimePeriod
-
getId
public long getId()
Return the id of this time period- Returns:
- id of this TimePeriod
-
getExternalId
public Object getExternalId()
Return the external id of this time period- Returns:
- external id of this TimePeriod
-
hasExternalId
public boolean hasExternalId()
Returns whether this time period has its external id set- Returns:
- true if the external Id has been set, false otherwise
-
compareTo
public int compareTo(TimePeriod o)
Compare this object with another TimePeriod object Comparison is based on start time and duration- Specified by:
compareToin interfaceComparable<TimePeriod>- Parameters:
o- TimePeriod this object is being compared to- Returns:
- result of comparison
- See Also:
Comparable.compareTo(java.lang.Object)
-
-