Class JavaTimes


  • public class JavaTimes
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      JavaTimes()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static TimeDuration age​(java.time.Instant instant)
      Calculates the age of a datetime from 'now'.
      static TimeDuration age​(java.time.Instant instant, long epochMillis)
      Calculates the age of a datetime against a reference epoch millis.
      static TimeDuration age​(java.time.ZonedDateTime dt)
      Calculates the age of a datetime from 'now'.
      static TimeDuration age​(java.time.ZonedDateTime dt, long epochMillis)
      Calculates the age of a datetime against a reference epoch millis.
      static boolean equals​(java.time.ZonedDateTime a, java.time.ZonedDateTime b)
      Tests equality (ignoring timezones).
      static boolean gt​(java.time.Instant a, java.time.Instant b)
      Is a value greater than b.
      static boolean gte​(java.time.Instant a, java.time.Instant b)
      Is a value greater than or equal to b.
      static boolean lt​(java.time.Instant a, java.time.Instant b)
      Is a value less than b.
      static boolean lte​(java.time.Instant a, java.time.Instant b)
      Is a value less than or equal to b.
      static java.time.Instant max​(java.time.Instant... dts)
      Returns the minimum of all instants.
      static java.time.Instant max​(java.time.Instant a, java.time.Instant b)
      Returns a if greater than or equal to b, otherwise b.
      static java.time.Instant min​(java.time.Instant... dts)
      Returns the minimum of all instants.
      static java.time.Instant min​(java.time.Instant a, java.time.Instant b)
      Returns a if less than or equal to b, otherwise b.
      static java.time.ZonedDateTime now()
      Returns now() in UTC.
      static boolean overlap​(java.time.Instant start1, java.time.Instant end1, java.time.Instant start2, java.time.Instant end2)
      Is there an overlap in range1 (start1 to end1) and range2 (start2 to end2) null values are treated as Instant.MIN for start and Instant.MAX for end.
      static boolean overlap​(java.time.Instant start1, java.time.Instant end1, java.time.Instant start2, java.time.Instant end2, boolean endInclusive)
      Is there an overlap in range1 (start1 to end1) and range2 (start2 to end2) null values are treated as Instant.MIN for start and Instant.MAX for end.
      static boolean overlap​(java.time.Instant start1, java.time.Instant end1, java.time.Instant start2, java.time.Instant end2, boolean startInclusive, boolean endInclusive)
      Is there an overlap in range1 (start1 to end1) and range2 (start2 to end2) null values are treated as Instant.MIN for start and Instant.MAX for end.
      static boolean sameMillisPrecision​(java.time.Instant a, java.time.Instant b, boolean rounding)
      Tests for similarity down to millisecond precision.
      static java.lang.String uptime​(java.lang.Long startEpochMillis)  
      static java.lang.String uptime​(java.lang.Long endEpochMillis, java.lang.Long startEpochMillis)  
      static java.lang.String uptime​(java.time.Duration duration)  
      static java.lang.String uptime​(java.time.Instant start)
      Formats a string of "uptime" relative to NOW such as "6m 1s 467ms"
      static java.lang.String uptime​(java.time.Instant end, java.time.Instant start)  
      static java.lang.String uptime​(java.time.ZonedDateTime start)  
      static java.lang.String uptime​(java.time.ZonedDateTime end, java.time.ZonedDateTime start)  
      static boolean within​(java.time.Instant dt, java.time.Instant start, java.time.Instant end)
      Whether instant is within start and end instants.
      static boolean within​(java.time.Instant dt, java.time.Instant start, java.time.Instant end, boolean endInclusive)
      Whether instant is within start and end instants.The min of start and end is detected so the ordering does not matter.
      static boolean within​(java.time.Instant dt, java.time.Instant start, java.time.Instant end, boolean startInclusive, boolean endInclusive)
      Whether instant is within start and end instants.The min of start and end is detected so the ordering does not matter.By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE/INCLUSIVE depending on what you pass in.
      static java.time.ZonedDateTime zonedDateTime​(java.time.Instant instant)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JavaTimes

        public JavaTimes()
    • Method Detail

      • zonedDateTime

        public static java.time.ZonedDateTime zonedDateTime​(java.time.Instant instant)
      • now

        public static java.time.ZonedDateTime now()
        Returns now() in UTC.
        Returns:
        Now in UTC
      • equals

        public static boolean equals​(java.time.ZonedDateTime a,
                                     java.time.ZonedDateTime b)
        Tests equality (ignoring timezones).
        Parameters:
        a -
        b -
        Returns:
      • sameMillisPrecision

        public static boolean sameMillisPrecision​(java.time.Instant a,
                                                  java.time.Instant b,
                                                  boolean rounding)
        Tests for similarity down to millisecond precision. Uses a truncating strategy for the "nanos" part of the value by default, unless rounding is true in which case the nanos may cause the millis to be also checked if they would round up.
        Parameters:
        a -
        b -
        rounding - If the nanos should be cause the milliseconds to be rounded up
        Returns:
        True if same moment in time otherwise false
      • age

        public static TimeDuration age​(java.time.Instant instant)
        Calculates the age of a datetime from 'now'. Just like your birthday, if the datetime is in the past then you a positive duration will be returned, if in the future then negative. For example, if the datetime is April 1 and 'now' is April 2, then the age will be a positive 1 day.
        Parameters:
        instant - The datetime to calculate the age of.
        Returns:
      • age

        public static TimeDuration age​(java.time.ZonedDateTime dt)
        Calculates the age of a datetime from 'now'. Just like your birthday, if the datetime is in the past then you a positive duration will be returned, if in the future then negative. For example, if the datetime is April 1 and 'now' is April 2, then the age will be a positive 1 day.
        Parameters:
        dt - The datetime to calculate the age of.
        Returns:
      • age

        public static TimeDuration age​(java.time.Instant instant,
                                       long epochMillis)
        Calculates the age of a datetime against a reference epoch millis. If the datetime is on April 1 and the epochMillis is on April 2, then the age will be a positive 1 day.
        Parameters:
        instant -
        epochMillis -
        Returns:
      • age

        public static TimeDuration age​(java.time.ZonedDateTime dt,
                                       long epochMillis)
        Calculates the age of a datetime against a reference epoch millis. If the datetime is on April 1 and the epochMillis is on April 2, then the age will be a positive 1 day.
        Parameters:
        dt -
        epochMillis -
        Returns:
      • uptime

        public static java.lang.String uptime​(java.time.Instant start)
        Formats a string of "uptime" relative to NOW such as "6m 1s 467ms"
        Parameters:
        start -
        Returns:
      • uptime

        public static java.lang.String uptime​(java.lang.Long startEpochMillis)
      • uptime

        public static java.lang.String uptime​(java.time.ZonedDateTime start)
      • uptime

        public static java.lang.String uptime​(java.time.ZonedDateTime end,
                                              java.time.ZonedDateTime start)
      • uptime

        public static java.lang.String uptime​(java.time.Instant end,
                                              java.time.Instant start)
      • uptime

        public static java.lang.String uptime​(java.lang.Long endEpochMillis,
                                              java.lang.Long startEpochMillis)
      • uptime

        public static java.lang.String uptime​(java.time.Duration duration)
      • min

        public static java.time.Instant min​(java.time.Instant a,
                                            java.time.Instant b)
        Returns a if less than or equal to b, otherwise b.
        Parameters:
        a -
        b -
        Returns:
      • min

        public static java.time.Instant min​(java.time.Instant... dts)
        Returns the minimum of all instants.
        Parameters:
        dts -
        Returns:
      • max

        public static java.time.Instant max​(java.time.Instant a,
                                            java.time.Instant b)
        Returns a if greater than or equal to b, otherwise b.
        Parameters:
        a -
        b -
        Returns:
      • max

        public static java.time.Instant max​(java.time.Instant... dts)
        Returns the minimum of all instants.
        Parameters:
        dts -
        Returns:
      • gt

        public static boolean gt​(java.time.Instant a,
                                 java.time.Instant b)
        Is a value greater than b. If a is not null and b is null then this is true.
        Parameters:
        a -
        b -
        Returns:
      • gte

        public static boolean gte​(java.time.Instant a,
                                  java.time.Instant b)
        Is a value greater than or equal to b. Will still be true if both values are null OR if a is non-null and b is null.
        Parameters:
        a -
        b -
        Returns:
      • lt

        public static boolean lt​(java.time.Instant a,
                                 java.time.Instant b)
        Is a value less than b. If b is not null and a is null then this is true.
        Parameters:
        a -
        b -
        Returns:
      • lte

        public static boolean lte​(java.time.Instant a,
                                  java.time.Instant b)
        Is a value less than or equal to b. Will still be true if both values are null OR if a is non-null and b is null.
        Parameters:
        a -
        b -
        Returns:
      • within

        public static boolean within​(java.time.Instant dt,
                                     java.time.Instant start,
                                     java.time.Instant end)
        Whether instant is within start and end instants. The min of start and end is detected so the ordering does not matter. By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE.
        Parameters:
        dt - The instant to check
        start - The start (or end) of the instant range
        end - The end (or start) of the instant range
        Returns:
        True if within range, otherwise false.
      • within

        public static boolean within​(java.time.Instant dt,
                                     java.time.Instant start,
                                     java.time.Instant end,
                                     boolean endInclusive)
        Whether instant is within start and end instants.The min of start and end is detected so the ordering does not matter. By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE/INCLUSIVE depending on what you pass in.
        Parameters:
        dt - The instant to check
        start - The start (or end) of the instant range
        end - The end (or start) of the instant range
        endInclusive - True if the end date is inclusive, otherwise exclusive.
        Returns:
        True if within range, otherwise false.
      • within

        public static boolean within​(java.time.Instant dt,
                                     java.time.Instant start,
                                     java.time.Instant end,
                                     boolean startInclusive,
                                     boolean endInclusive)
        Whether instant is within start and end instants.The min of start and end is detected so the ordering does not matter.By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE/INCLUSIVE depending on what you pass in.
        Parameters:
        dt - The instant to check
        start - The start (or end) of the instant range
        end - The end (or start) of the instant range
        startInclusive - True if the start date is inclusive, otherwise exclusive.
        endInclusive - True if the end date is inclusive, otherwise exclusive.
        Returns:
        True if within range, otherwise false.
      • overlap

        public static boolean overlap​(java.time.Instant start1,
                                      java.time.Instant end1,
                                      java.time.Instant start2,
                                      java.time.Instant end2)
        Is there an overlap in range1 (start1 to end1) and range2 (start2 to end2) null values are treated as Instant.MIN for start and Instant.MAX for end. By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE.
        Parameters:
        start1 - - start of range1
        end1 - - end of range1
        start2 - - start of range2
        end2 - - end of range2
        Returns:
        boolean
      • overlap

        public static boolean overlap​(java.time.Instant start1,
                                      java.time.Instant end1,
                                      java.time.Instant start2,
                                      java.time.Instant end2,
                                      boolean endInclusive)
        Is there an overlap in range1 (start1 to end1) and range2 (start2 to end2) null values are treated as Instant.MIN for start and Instant.MAX for end. By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE.
        Parameters:
        start1 - - start of range1
        end1 - - end of range1
        start2 - - start of range2
        end2 - - end of range2
        endInclusive - True if the end date is inclusive, otherwise exclusive.
        Returns:
        boolean
      • overlap

        public static boolean overlap​(java.time.Instant start1,
                                      java.time.Instant end1,
                                      java.time.Instant start2,
                                      java.time.Instant end2,
                                      boolean startInclusive,
                                      boolean endInclusive)
        Is there an overlap in range1 (start1 to end1) and range2 (start2 to end2) null values are treated as Instant.MIN for start and Instant.MAX for end. By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE.
        Parameters:
        start1 - - start of range1
        end1 - - end of range1
        start2 - - start of range2
        end2 - - end of range2
        startInclusive - True if the start date is inclusive, otherwise exclusive.
        endInclusive - True if the end date is inclusive, otherwise exclusive.
        Returns:
        boolean