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 int
compareTo(TimePeriod o)
Compare this object with another TimePeriod object Comparison is based on start time and durationstatic long
convertHoursToSeconds(double hoursFromMidnight)
Convert hours to (whole) secondsstatic long
convertHoursToSeconds(String fourDigitHour)
Convert duration to seconds given start time using the 24-hour clockstatic float
convertSecondsToHours(int secondsFromMidnight)
Convert seconds to 24h format from midnight to secondsString
getDescription()
Return the descriptionlong
getDurationSeconds()
Return the duration in secondsObject
getExternalId()
Return the external id of this time periodlong
getId()
Return the id of this time periodlong
getStartTimeSeconds()
Return the start timeboolean
hasExternalId()
Returns whether this time period has its external id setString
toString()
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:
compareTo
in interfaceComparable<TimePeriod>
- Parameters:
o
- TimePeriod this object is being compared to- Returns:
- result of comparison
- See Also:
Comparable.compareTo(java.lang.Object)
-
-