Class ExtendedLocalTime

  • All Implemented Interfaces:
    Comparable<ExtendedLocalTime>

    public class ExtendedLocalTime
    extends Object
    implements Comparable<ExtendedLocalTime>
    Simple immutable extension to Local Time to allow for additional time beyond midnight within a single time entity, e.g. 25:01:01 (HH:mm:ss).

    This class does not support nano seconds and only allows for time to be expanded up to hour 47, i.e., not beyond another midnight. Also we only support strings to be parsed and output of the form HH:mm:ss, to keep things simple

    • Method Detail

      • isNanosValid

        public static boolean isNanosValid​(long nanos)
        Verify if nanos are valid, i.e., within 48h and not negative
        Parameters:
        nanos - to verify
        Returns:
        true when valid, false otherwise
      • of

        public static ExtendedLocalTime of​(LocalTime localtime)
        Create extended local time from regular local time
        Parameters:
        localtime - to use as base for new extende local time
        Returns:
        created extended local time
      • of

        public static ExtendedLocalTime of​(long nanos)
        Create from nanos, logs warning and returns null if not valid
        Parameters:
        nanos - to use
        Returns:
        created extended local time
      • ofBeyondMidnight

        public static ExtendedLocalTime ofBeyondMidnight​(LocalTime localtime)
        Create extended local time from regular local time that is assumed to be beyond midnight
        Parameters:
        localtime - to use as base for new extende local time
        Returns:
        created extended local time
      • of

        public static ExtendedLocalTime of​(String hh_mm_ss)
        Factory method taking HH:mm:ss where hours are allowed to exceed 24 to reflect a time running passed the day (but not beyond the next day), e.g. it should be less than 48
        Parameters:
        hh_mm_ss - string to extract time from
        Returns:
        created extended local time
      • exceedsSingleDay

        public boolean exceedsSingleDay()
        Check if extended time exceeds midnight, i.e. hour is smaller than 47 and greater than 23
        Returns:
        true when extended beyond midnight, false otherwise
      • asLocalTimeBeforeMidnight

        public LocalTime asLocalTimeBeforeMidnight()
        Extract the component before midnight as a new LocalTime instance
        Returns:
        created local time based on time before midnight
      • asLocalTimeAfterMidnight

        public LocalTime asLocalTimeAfterMidnight()
        Extract the component after midnight as a new LocalTime instance
        Returns:
        created local time based on time after midnight, null if time does not exceed single day
      • isBefore

        public boolean isBefore​(ExtendedLocalTime other)
        verify if other time occurs before this time
        Parameters:
        other - to compare to
        Returns:
        true when before, false otherwise
      • isAfter

        public boolean isAfter​(ExtendedLocalTime other)
        verify if other time occurs before this time
        Parameters:
        other - to compare to
        Returns:
        true when before, false otherwise
      • minus

        public ExtendedLocalTime minus​(ExtendedLocalTime other)
        subtract other from this and return newly created extended time reflecting the new time. One cannot subtract to invalid time, e.g. negative time is not allowed, so this time must be larger than other
        Parameters:
        other - to subtract
        Returns:
        newly created time, null if invalid
      • plus

        public ExtendedLocalTime plus​(ExtendedLocalTime other)
        add other to this and return newly created extended time reflecting the new time. One cannot add to invalid time, e.g., negative time is not allowed, so this time must be larger than other
        Parameters:
        other - to subtract
        Returns:
        newly created time, null if invalid
      • toNanoOfExtendedDay

        public long toNanoOfExtendedDay()
        get nanos of this extended time
        Returns:
        nanos
      • toString

        public String toString()
        As string
        Overrides:
        toString in class Object
        Returns:
        hh:mm:ss format
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object