Class 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 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 class
        externalId - externalId of this time period
        startTimeSeconds - start time in seconds from midnight
        durationSeconds - 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 class
        externalId - externalId of this time period
        description - description of this time period
        startTimeSeconds - start time of this time period
        durationSeconds - 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
      • toString

        public String toString()
        Output this object as a String
        Overrides:
        toString in class Object
        Returns:
        String containing the value of this TimePeriod