Class DateUtil

java.lang.Object
com.ssgllc.fish.service.util.registered.DateUtil

@Component public final class DateUtil extends Object
  • Field Details

    • DEFAULT_DATE_PATTERN

      public static String DEFAULT_DATE_PATTERN
  • Method Details

    • setDatabase

      @Value("${casetivity.dateFormat}") public void setDatabase(String dateFormat)
    • getLocalDateFromJodaDate

      public static LocalDate getLocalDateFromJodaDate(Object jodaDate)
    • getLocalDateFromInstant

      public static LocalDate getLocalDateFromInstant(Object instantObj)
    • getLocalDateFromDate

      public static LocalDate getLocalDateFromDate(Object date)
    • getDate

      public static Date getDate(Object date)
      Converts the given object into a Date object. This method attempts to interpret the input object as a valid date representation and convert it into a Date. The supported input types are:
      • Date - Returns the input as is.
      • LocalDate - Converts to a Date using the system's default timezone.
      • LocalDate - Converts to a Date using the system's default timezone.
      • Instant - Converts to a Date preserving the UTC representation.
      • String - Attempts to parse the string into a Date, assuming it is in the default date format or ISO-8601.
      • Long - Treats the long value as an epoch timestamp in milliseconds.
      Note: For string inputs, the behavior may vary depending on the format and timezone assumptions. Strings like "2024-12-13" will typically be treated as UTC midnight by default. When using this method with strings, ensure you provide input consistent with the expected behavior. If your input string is not in UTC, consider using getDate(getLocalDate(string)) to handle timezone correctly.
      Parameters:
      date - the object to convert to a Date, or null
      Returns:
      the resulting Date, or null if the input could not be converted
    • getDateFromInstant

      public static Date getDateFromInstant(Object instantObj)
    • getDateFromLocalDate

      public static Date getDateFromLocalDate(Object localDate)
    • setTimeToNoon

      public static Date setTimeToNoon(Date date)
    • getDateFromJodaDate

      public static Date getDateFromJodaDate(Object jodaDate)
    • isDate

      public static boolean isDate(Object date)
    • getLocalDate

      public static LocalDate getLocalDate(Object date)
    • getLocalDateFromObject

      public static LocalDate getLocalDateFromObject(Object date)
    • getStringFromDate

      public static String getStringFromDate(Object date, String format)
    • getDateFromStringObject

      public static LocalDate getDateFromStringObject(Object date)
    • getDateFromString

      public static LocalDate getDateFromString(String date, String format)
    • isStringValidDate

      public static boolean isStringValidDate(String date, String format)
      Checks if a given string can be parsed into a date using the specified format.
      Parameters:
      date - The date string to validate.
      format - The date format pattern.
      Returns:
      true if parsing succeeds; false otherwise.

      Groovy example:
      return stringUtil.isStringValidDate("2025-07-02", "yyyy-MM-dd")

      Returns:
      true

      SpEL example:
      #isStringValidDate("2025-07-02", "yyyy-MM-dd")

      Returns:
      true

      Note: If date is null or cannot be parsed according to format, this method returns false.
    • isStringValidDateStrict

      public static boolean isStringValidDateStrict(String date, String format)
      Checks if a given string strictly matches the specified date format, rejecting “smart” adjustments (e.g., non-leap-year February 29).
      Uses ResolverStyle.STRICT to enforce exact date matching.
      Note: the year pattern should be uuuu instead of yyyy, because y represents “year-of-era” and expects an era designator (e.g., AD/BC).
      Parameters:
      date - The date string to validate.
      format - The date format pattern to enforce.
      Returns:
      true if strict parsing succeeds; false otherwise.

      Groovy example:
      // Feb 29, 2025 is invalid because 2025 is not a leap year return stringUtil.isStringValidDateStrict('02/29/2025', 'MM/dd/uuuu')

      Returns:
      false

      SpEL example:
      #isStringValidDateStrict('02/29/2025', 'MM/dd/uuuu')

      Returns:
      false

      Note: Returns false if date is null or does not strictly conform to the given format (including invalid leap-year dates).
    • getStringFromInstant

      public static String getStringFromInstant(Instant instant, String pattern)
    • getStringFromInstantPatterned

      public static String getStringFromInstantPatterned(Instant instant)
    • getInstantFromString

      public static Instant getInstantFromString(String instantStr)
    • getLocalStrFromUtcInstant

      public static String getLocalStrFromUtcInstant(Instant utcInstant)
    • addDaysObjToDate

      public static LocalDate addDaysObjToDate(LocalDate date, Object daysObj)
    • addDaysToDate

      public static LocalDate addDaysToDate(LocalDate date, Integer days)
    • addMonthsObjToDate

      public static Object addMonthsObjToDate(LocalDate date, Object monthsObj)
    • addMonthsToDate

      public static Object addMonthsToDate(LocalDate date, Integer months)
    • addYearsObjToDate

      public static Object addYearsObjToDate(LocalDate date, Object yearsObj)
    • addYearsToDate

      public static Object addYearsToDate(LocalDate date, Integer years)
    • daysBetweenObj

      public static Long daysBetweenObj(Object firstDateObj, Object secondDateObj, boolean includeWeekendDays)
    • monthsBetweenObj

      public static Long monthsBetweenObj(Object firstDateObj, Object secondDateObj)
    • yearsBetweenObj

      public static Long yearsBetweenObj(Object firstDateObj, Object secondDateObj)
    • createDateFromYearMonthDay

      public static LocalDate createDateFromYearMonthDay(Integer year, Integer month, Integer day)
    • convertFormatObject

      public static String convertFormatObject(Object dateObj, String fromFormat, String toFormat)
    • convertFormatsObject

      public static String convertFormatsObject(Object dateObj, String[] fromFormats, String toFormat)
    • convertFormat

      public static String convertFormat(String date, String fromFormat, String toFormat)
    • isTodayStrPatterned

      @Deprecated public static Boolean isTodayStrPatterned(String dateString)
      Deprecated.
    • beforeTodayStrPatterned

      @Deprecated public static Boolean beforeTodayStrPatterned(String dateString)
      Deprecated.
    • beforeOrEqualsTodayStrPatterned

      @Deprecated public static Boolean beforeOrEqualsTodayStrPatterned(String dateString)
      Deprecated.
    • afterTodayStrPatterned

      @Deprecated public static Boolean afterTodayStrPatterned(String dateString)
      Deprecated.
    • afterOrEqualsTodayStrPatterned

      @Deprecated public static Boolean afterOrEqualsTodayStrPatterned(String dateString)
      Deprecated.
    • compareDate

      public static int compareDate(Instant dateOne, Instant dateTwo)
    • isTodayStr

      @Deprecated public static Boolean isTodayStr(String dateString, String pattern)
      Deprecated.
    • beforeTodayStr

      @Deprecated public static Boolean beforeTodayStr(String dateString, String pattern)
      Deprecated.
    • beforeOrEqualsTodayStr

      @Deprecated public static Boolean beforeOrEqualsTodayStr(String dateString, String pattern)
      Deprecated.
    • afterTodayStr

      @Deprecated public static Boolean afterTodayStr(String dateString, String pattern)
      Deprecated.
    • afterOrEqualsTodayStr

      @Deprecated public static Boolean afterOrEqualsTodayStr(String dateString, String pattern)
      Deprecated.
    • sameDateStrPatterned

      @Deprecated public static Boolean sameDateStrPatterned(String dateOneStr, String dateTwoStr)
      Deprecated.
    • beforeDateStrPatterned

      @Deprecated public static Boolean beforeDateStrPatterned(String dateOneStr, String dateTwoStr)
      Deprecated.
    • beforeOrEqualsDateStrPatterned

      @Deprecated public static Boolean beforeOrEqualsDateStrPatterned(String dateOneStr, String dateTwoStr)
      Deprecated.
    • afterDateStrPatterned

      @Deprecated public static Boolean afterDateStrPatterned(String dateOneStr, String dateTwoStr)
      Deprecated.
    • afterOrEqualsDateStrPatterned

      @Deprecated public static Boolean afterOrEqualsDateStrPatterned(String dateOneStr, String dateTwoStr)
      Deprecated.
    • sameDateStr

      public static Boolean sameDateStr(String dateOneStr, String dateTwoStr, String pattern)
    • beforeDateStr

      public static Boolean beforeDateStr(String dateOneStr, String dateTwoStr, String pattern)
    • beforeOrEqualsDateStr

      public static Boolean beforeOrEqualsDateStr(String dateOneStr, String dateTwoStr, String pattern)
    • afterDateStr

      public static Boolean afterDateStr(String dateOneStr, String dateTwoStr, String pattern)
    • afterOrEqualsDateStr

      public static Boolean afterOrEqualsDateStr(String dateOneStr, String dateTwoStr, String pattern)
    • isToday

      public static Boolean isToday(LocalDate date)
    • beforeToday

      public static Boolean beforeToday(LocalDate date)
    • beforeOrEqualsToday

      public static Boolean beforeOrEqualsToday(LocalDate date)
    • afterToday

      public static Boolean afterToday(LocalDate date)
    • afterOrEqualsToday

      public static Boolean afterOrEqualsToday(LocalDate date)
    • sameDate

      public static Boolean sameDate(LocalDate dateOne, LocalDate dateTwo)
    • beforeDate

      public static Boolean beforeDate(LocalDate dateOne, LocalDate dateTwo)
    • beforeOrEqualsDate

      public static Boolean beforeOrEqualsDate(LocalDate dateOne, LocalDate dateTwo)
    • afterDate

      public static Boolean afterDate(LocalDate dateOne, LocalDate dateTwo)
    • afterOrEqualsDate

      public static Boolean afterOrEqualsDate(LocalDate dateOne, LocalDate dateTwo)
    • startOfToday

      public static Instant startOfToday()
    • endOfToday

      public static Instant endOfToday()
    • beforeTodayInst

      public static Boolean beforeTodayInst(Instant date)
    • beforeOrEqualsTodayInst

      public static Boolean beforeOrEqualsTodayInst(Instant date)
    • afterTodayInst

      public static Boolean afterTodayInst(Instant date)
    • afterOrEqualsTodayInst

      public static Boolean afterOrEqualsTodayInst(Instant date)
    • beforeInstant

      public static Boolean beforeInstant(Instant dateOne, Instant dateTwo)
    • afterInstant

      public static Boolean afterInstant(Instant dateOne, Instant dateTwo)
    • addHours

      public static Instant addHours(Instant date, long hours)
    • addMinutes

      public static Instant addMinutes(Instant date, long minutes)
    • addSeconds

      public static Instant addSeconds(Instant date, long seconds)
    • compareLocalDate

      public static Boolean compareLocalDate(LocalDate dateOne, LocalDate dateTwo, String operator)
    • compareDateStr

      @Deprecated public static Boolean compareDateStr(String dateOneStr, String dateTwoStr, String pattern, String operator)
      Deprecated.
    • addDaysToDateStr

      @Deprecated public static String addDaysToDateStr(String dateStr, Integer days)
      Deprecated.
    • addMonthsToDateStr

      @Deprecated public static String addMonthsToDateStr(String dateStr, Integer months)
      Deprecated.
    • addYearsToDateStr

      @Deprecated public static String addYearsToDateStr(String dateStr, Integer years)
      Deprecated.
    • today

      @Deprecated public static String today()
      Deprecated.
    • todayDate

      @Deprecated public static LocalDate todayDate()
      Deprecated.
    • now

      @Deprecated public static String now()
      Deprecated.
    • instantNow

      @Deprecated public static Instant instantNow()
      Deprecated.
    • daysBetween

      public static Integer daysBetween(LocalDate dateOne, LocalDate dateTwo)
    • weekdaysBetween

      public static Integer weekdaysBetween(LocalDate dateOne, LocalDate dateTwo)
    • monthsBetween

      public static Long monthsBetween(LocalDate dateOne, LocalDate dateTwo)
    • yearsBetween

      public static Long yearsBetween(LocalDate dateOne, LocalDate dateTwo)
    • getDaysBetween

      public static Integer getDaysBetween(LocalDate dateOne, LocalDate dateTwo, boolean includeWeekendDays)
    • daysBetweenStr

      @Deprecated public static Integer daysBetweenStr(String dateOneStr, String dateTwoStr, boolean includeWeekdays)
      Deprecated.
    • getInstantFromDate

      public static Instant getInstantFromDate(Date date)
    • getInstantFromObject

      public static Instant getInstantFromObject(Object object)
    • getIsoDateTimeString

      public static String getIsoDateTimeString(Object object)
    • elapsedBetweenTimes

      public static Long elapsedBetweenTimes(String hhmmss1, String hhmmss2, String units)
    • randomDate

      public static LocalDate randomDate(LocalDate from, LocalDate to)
    • getYearOfDateByWeeks

      public static Integer getYearOfDateByWeeks(LocalDate date)
    • getStartDateOfYearByWeeks

      public static LocalDate getStartDateOfYearByWeeks(int year)
    • getWeekOfDateByWeeks

      public static Integer getWeekOfDateByWeeks(LocalDate date)
    • createDateRange

      public static List<LocalDate> createDateRange(Object minValueInput, Object maxValueInput)