Class DateTimeUtils


  • public class DateTimeUtils
    extends java.lang.Object
    Utilities methods and constants related to Joda DateTime objects.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.joda.time.DateTime END_OF_TIME
      A date in the far future that we can treat as infinity.
      static org.joda.time.DateTime START_OF_TIME
      The start of the epoch, in a convenient constant.
    • Constructor Summary

      Constructors 
      Constructor Description
      DateTimeUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.joda.time.DateTime earliestOf​(java.lang.Iterable<org.joda.time.DateTime> dates)
      Returns the earliest element in a DateTime iterable.
      static org.joda.time.DateTime earliestOf​(org.joda.time.DateTime first, org.joda.time.DateTime... rest)
      Returns the earliest of a number of given DateTime instances.
      static boolean isAtOrAfter​(org.joda.time.DateTime timeToCheck, org.joda.time.DateTime timeToCompareTo)
      Returns whether the first DateTime is equal to or later than the second.
      static boolean isBeforeOrAt​(org.joda.time.DateTime timeToCheck, org.joda.time.DateTime timeToCompareTo)
      Returns whether the first DateTime is equal to or earlier than the second.
      static org.joda.time.DateTime latestOf​(java.lang.Iterable<org.joda.time.DateTime> dates)
      Returns the latest element in a DateTime iterable.
      static org.joda.time.DateTime latestOf​(org.joda.time.DateTime first, org.joda.time.DateTime... rest)
      Returns the latest of a number of given DateTime instances.
      static org.joda.time.DateTime leapSafeAddYears​(org.joda.time.DateTime now, int years)
      Adds years to a date, in the Duration sense of semantic years.
      static org.joda.time.DateTime leapSafeSubtractYears​(org.joda.time.DateTime now, int years)
      Subtracts years from a date, in the Duration sense of semantic years.
      static org.joda.time.DateTime toJodaDateTime​(java.time.ZonedDateTime zonedDateTime)
      Converts a java.time ZonedDateTime object to an equivalent Joda DateTime object.
      static org.joda.time.LocalDate toLocalDate​(java.sql.Date date)  
      static java.sql.Date toSqlDate​(org.joda.time.LocalDate localDate)  
      static java.time.ZonedDateTime toZonedDateTime​(org.joda.time.DateTime dateTime)
      Converts a Joda DateTime object to an equivalent java.time ZonedDateTime object.
      • Methods inherited from class java.lang.Object

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

      • START_OF_TIME

        public static final org.joda.time.DateTime START_OF_TIME
        The start of the epoch, in a convenient constant.
      • END_OF_TIME

        public static final org.joda.time.DateTime END_OF_TIME
        A date in the far future that we can treat as infinity.

        This value is (2^63-1)/1000 rounded down. AppEngine stores dates as 64 bit microseconds, but Java uses milliseconds, so this is the largest representable date that will survive a round-trip through Datastore.

    • Constructor Detail

      • DateTimeUtils

        public DateTimeUtils()
    • Method Detail

      • earliestOf

        public static org.joda.time.DateTime earliestOf​(org.joda.time.DateTime first,
                                                        org.joda.time.DateTime... rest)
        Returns the earliest of a number of given DateTime instances.
      • earliestOf

        public static org.joda.time.DateTime earliestOf​(java.lang.Iterable<org.joda.time.DateTime> dates)
        Returns the earliest element in a DateTime iterable.
      • latestOf

        public static org.joda.time.DateTime latestOf​(org.joda.time.DateTime first,
                                                      org.joda.time.DateTime... rest)
        Returns the latest of a number of given DateTime instances.
      • latestOf

        public static org.joda.time.DateTime latestOf​(java.lang.Iterable<org.joda.time.DateTime> dates)
        Returns the latest element in a DateTime iterable.
      • isBeforeOrAt

        public static boolean isBeforeOrAt​(org.joda.time.DateTime timeToCheck,
                                           org.joda.time.DateTime timeToCompareTo)
        Returns whether the first DateTime is equal to or earlier than the second.
      • isAtOrAfter

        public static boolean isAtOrAfter​(org.joda.time.DateTime timeToCheck,
                                          org.joda.time.DateTime timeToCompareTo)
        Returns whether the first DateTime is equal to or later than the second.
      • leapSafeAddYears

        public static org.joda.time.DateTime leapSafeAddYears​(org.joda.time.DateTime now,
                                                              int years)
        Adds years to a date, in the Duration sense of semantic years. Use this instead of DateTime.plusYears(int) to ensure that we never end up on February 29.
      • leapSafeSubtractYears

        public static org.joda.time.DateTime leapSafeSubtractYears​(org.joda.time.DateTime now,
                                                                   int years)
        Subtracts years from a date, in the Duration sense of semantic years. Use this instead of DateTime.minusYears(int) to ensure that we never end up on February 29.
      • toZonedDateTime

        public static java.time.ZonedDateTime toZonedDateTime​(org.joda.time.DateTime dateTime)
        Converts a Joda DateTime object to an equivalent java.time ZonedDateTime object.
      • toJodaDateTime

        public static org.joda.time.DateTime toJodaDateTime​(java.time.ZonedDateTime zonedDateTime)
        Converts a java.time ZonedDateTime object to an equivalent Joda DateTime object.
      • toSqlDate

        public static java.sql.Date toSqlDate​(org.joda.time.LocalDate localDate)
      • toLocalDate

        public static org.joda.time.LocalDate toLocalDate​(java.sql.Date date)