Class DateStringUtils

java.lang.Object
com.illumon.util.calendar.DateStringUtils

public class DateStringUtils
extends Object
Basic utilities for Date Strings. To comply with the ISO-8601 standard for dates, Strings should be of the form "yyyy-MM-dd" Quiet methods are functionally equivalent to their counterparts, but assume Date String validity to remove the overhead of checking.
  • Method Details

    • minusDays

      public static String minusDays​(String date, int days)
      Subtract a number of days from a given date.
      Parameters:
      date - date
      days - days to subtract
      Returns:
      the day days before date
    • minusDaysQuiet

      public static String minusDaysQuiet​(String date, int days)
      Subtract a number of days from a given date. This does not check that dates are formatted correctly.
      Parameters:
      date - date
      days - days to subtract
      Returns:
      the day days before date
    • plusDays

      public static String plusDays​(String date, int days)
      Add a number of days from a given date.
      Parameters:
      date - date
      days - days to add
      Returns:
      the day days after date
    • plusDaysQuiet

      public static String plusDaysQuiet​(String date, int days)
      Add a number of days from a given date. This does not check that dates are formatted correctly.
      Parameters:
      date - date
      days - days to add
      Returns:
      the day days after date
    • isBefore

      public static boolean isBefore​(String date1, String date2)
      Is one date before another?
      Parameters:
      date1 - if null return false
      date2 - if null return false
      Returns:
      true if date1 is chronologically before date2; false otherwise.
    • isBeforeQuiet

      public static boolean isBeforeQuiet​(String date1, String date2)
      Is one date before another? This does not check that dates are formatted correctly. Could be disastrous if date1 and date2 are not ISO-8601 compliant!
      Parameters:
      date1 - if null return false
      date2 - if null return false
      Returns:
      true if date1 is chronologically before date2; false otherwise.
    • isAfter

      public static boolean isAfter​(String date1, String date2)
      Is one date after another?
      Parameters:
      date1 - if null return false
      date2 - if null return false
      Returns:
      true if date1 is chronologically after date2; false otherwise.
    • isAfterQuiet

      public static boolean isAfterQuiet​(String date1, String date2)
      Is one date after another? This does not check that dates are formatted correctly. Could be disastrous if date1 and date2 are not ISO-8601 compliant!
      Parameters:
      date1 - if null return false
      date2 - if null return false
      Returns:
      true if date1 is chronologically after date2; false otherwise.
    • monthOfYear

      public static int monthOfYear​(String date)
      Gets the month of the year for the date.
      Parameters:
      date - date; if null return NULL_INT
      Returns:
      month of the year for the date. Jan = 1, Dec = 12