Class DateMath


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

      • DateMath

        public DateMath()
    • Method Detail

      • addDays

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

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

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

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

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

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

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

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

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