Class DateMath


  • public class DateMath
    extends java.lang.Object
    Simple utility class to handle the date arithmetic we need for rolling date-based partitions TODO use java.time instead
    • Constructor Summary

      Constructors 
      Constructor Description
      DateMath()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Date addDays​(java.util.Date d, int howMany)
      Add howMany days to the given Date
      static java.util.Date addMonths​(java.util.Date d, int howMany)
      Add howMany months to the given Date
      static java.util.Date addSeconds​(java.util.Date d, int howMany)
      Add the requested number of seconds to the given date
      static java.lang.String format​(java.util.Date d)
      Format the date value as yyyy-MM-dd
      static java.lang.String format2​(java.util.Date d)
      Alternate format of the date value: yyyyMMdd
      static java.util.Date max​(java.util.Date d1, java.util.Date d2)
      Return the max of 2 dates
      static java.util.Date parse​(java.lang.String str)
      Parse the date string which is expected to be yyyy-MM-dd
      static java.util.Date truncateToDay​(java.util.Date d)
      Truncate the date to the beginning of the day
      static java.util.Date truncateToMonth​(java.util.Date d)
      Truncate the date to the midnight on the first day of the month
      • Methods inherited from class java.lang.Object

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

      • DateMath

        public DateMath()
    • Method Detail

      • addDays

        public static java.util.Date addDays​(java.util.Date d,
                                             int howMany)
        Add howMany days to the given Date
        Parameters:
        d -
        howMany -
        Returns:
      • addMonths

        public static java.util.Date addMonths​(java.util.Date d,
                                               int howMany)
        Add howMany months to the given Date
        Parameters:
        d -
        howMany -
        Returns:
      • parse

        public static java.util.Date parse​(java.lang.String str)
        Parse the date string which is expected to be yyyy-MM-dd
        Parameters:
        str -
        Returns:
      • format

        public static java.lang.String format​(java.util.Date d)
        Format the date value as yyyy-MM-dd
        Parameters:
        d -
        Returns:
      • format2

        public static java.lang.String format2​(java.util.Date d)
        Alternate format of the date value: yyyyMMdd
        Parameters:
        d -
        Returns:
      • truncateToMonth

        public static java.util.Date truncateToMonth​(java.util.Date d)
        Truncate the date to the midnight on the first day of the month
        Parameters:
        d -
        Returns:
      • truncateToDay

        public static java.util.Date truncateToDay​(java.util.Date d)
        Truncate the date to the beginning of the day
        Parameters:
        d -
        Returns:
      • addSeconds

        public static java.util.Date addSeconds​(java.util.Date d,
                                                int howMany)
        Add the requested number of seconds to the given date
        Parameters:
        d -
        howMany -
        Returns:
      • max

        public static java.util.Date max​(java.util.Date d1,
                                         java.util.Date d2)
        Return the max of 2 dates
        Parameters:
        d1 -
        d2 -
        Returns:
        max date