Class DateTimes


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

      Constructors 
      Constructor Description
      DateTimes()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static TimeDuration age​(org.joda.time.DateTime dt)
      Calculates the age of a datetime from 'now'.
      static TimeDuration age​(org.joda.time.DateTime dt, long epochMillis)
      Calculates the age of a datetime against a reference epoch millis.
      static org.joda.time.DateTime dateTime​(java.time.Instant instant)  
      static boolean equals​(org.joda.time.DateTime a, org.joda.time.DateTime b)
      Tests equality (ignoring timezones).
      static boolean gt​(org.joda.time.DateTime a, org.joda.time.DateTime b)
      Is a value greater than b.
      static boolean gte​(org.joda.time.DateTime a, org.joda.time.DateTime b)
      Is a value greater than or equal to b.
      static java.time.Duration javaDuration​(org.joda.time.Duration duration)  
      static java.time.Instant javaInstant​(org.joda.time.DateTime dt)  
      static boolean lt​(org.joda.time.DateTime a, org.joda.time.DateTime b)
      Is a value less than b.
      static boolean lte​(org.joda.time.DateTime a, org.joda.time.DateTime b)
      Is a value less than or equal to b.
      static org.joda.time.DateTime max​(org.joda.time.DateTime... dts)
      Returns the minimum of all datetimes.
      static org.joda.time.DateTime max​(org.joda.time.DateTime a, org.joda.time.DateTime b)
      Returns a if greater than or equal to b, otherwise b.
      static org.joda.time.DateTime min​(org.joda.time.DateTime... dts)
      Returns the minimum of all datetimes.
      static org.joda.time.DateTime min​(org.joda.time.DateTime a, org.joda.time.DateTime b)
      Returns a if less than or equal to b, otherwise b.
      static org.joda.time.DateTime now()
      Returns now() in UTC.
      static java.lang.String uptime​(org.joda.time.DateTime dt)
      Formats a string of "uptime" relative to NOW such as "6m 1s 467ms"
      static java.lang.String uptime​(org.joda.time.DateTime end, org.joda.time.DateTime start)  
      static java.lang.String uptime​(org.joda.time.Duration duration)  
      static org.joda.time.DateTime utc​(org.joda.time.DateTime dt)
      Returns a new DateTime in UTC.
      static boolean within​(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end)
      Whether datetime is within start and end datetimes.
      static boolean within​(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end, boolean endInclusive)
      Whether datetime is within start and end datetimes.The min of start and end is detected so the ordering does not matter.
      static boolean within​(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end, boolean startInclusive, boolean endInclusive)
      Whether datetime is within start and end datetimes.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.
      • Methods inherited from class java.lang.Object

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

      • DateTimes

        public DateTimes()
    • Method Detail

      • dateTime

        public static org.joda.time.DateTime dateTime​(java.time.Instant instant)
      • javaInstant

        public static java.time.Instant javaInstant​(org.joda.time.DateTime dt)
      • javaDuration

        public static java.time.Duration javaDuration​(org.joda.time.Duration duration)
      • now

        public static org.joda.time.DateTime now()
        Returns now() in UTC.
        Returns:
        Now in UTC
      • utc

        public static org.joda.time.DateTime utc​(org.joda.time.DateTime dt)
        Returns a new DateTime in UTC.
        Parameters:
        dt -
        Returns:
      • equals

        public static boolean equals​(org.joda.time.DateTime a,
                                     org.joda.time.DateTime b)
        Tests equality (ignoring timezones).
        Parameters:
        a -
        b -
        Returns:
      • min

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

        public static org.joda.time.DateTime min​(org.joda.time.DateTime... dts)
        Returns the minimum of all datetimes.
        Parameters:
        dts -
        Returns:
      • max

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

        public static org.joda.time.DateTime max​(org.joda.time.DateTime... dts)
        Returns the minimum of all datetimes.
        Parameters:
        dts -
        Returns:
      • gt

        public static boolean gt​(org.joda.time.DateTime a,
                                 org.joda.time.DateTime 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​(org.joda.time.DateTime a,
                                  org.joda.time.DateTime 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​(org.joda.time.DateTime a,
                                 org.joda.time.DateTime 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​(org.joda.time.DateTime a,
                                  org.joda.time.DateTime 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:
      • age

        public static TimeDuration age​(org.joda.time.DateTime 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​(org.joda.time.DateTime 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:
      • within

        public static boolean within​(org.joda.time.DateTime dt,
                                     org.joda.time.DateTime start,
                                     org.joda.time.DateTime end)
        Whether datetime is within start and end datetimes. 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 datetime to check
        start - The start (or end) of the datetime range
        end - The end (or start) of the datetime range
        Returns:
        True if within range, otherwise false.
      • within

        public static boolean within​(org.joda.time.DateTime dt,
                                     org.joda.time.DateTime start,
                                     org.joda.time.DateTime end,
                                     boolean endInclusive)
        Whether datetime is within start and end datetimes.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 datetime to check
        start - The start (or end) of the datetime range
        end - The end (or start) of the datetime range
        endInclusive - True if the end date is inclusive, otherwise exclusive.
        Returns:
        True if within range, otherwise false.
      • within

        public static boolean within​(org.joda.time.DateTime dt,
                                     org.joda.time.DateTime start,
                                     org.joda.time.DateTime end,
                                     boolean startInclusive,
                                     boolean endInclusive)
        Whether datetime is within start and end datetimes.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 datetime to check
        start - The start (or end) of the datetime range
        end - The end (or start) of the datetime 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.
      • uptime

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

        public static java.lang.String uptime​(org.joda.time.DateTime end,
                                              org.joda.time.DateTime start)
      • uptime

        public static java.lang.String uptime​(org.joda.time.Duration duration)