Class DateUtil

java.lang.Object
org.broadleafcommerce.common.util.DateUtil

public class DateUtil extends Object
  • Field Details

  • Constructor Details

    • DateUtil

      public DateUtil()
  • Method Details

    • isActive

      public static boolean isActive(Date startDate, Date endDate, boolean includeTime)
      Determine if a date range is active.

      A date range is active if the following statement is true: startDate < now <= endDate

      If startDate is null then the date range is inactive. If endDate is null, then only the startDate is checked.

      Parameters:
      includeTime - If true, then the full timestamp to the millisecond is used. If false, only the date will be used and the time is zeroed out.
      Returns:
      True if the date range is currently active, false otherwise.
    • getCurrentDateAfterFactoringInDateResolution

      public static Date getCurrentDateAfterFactoringInDateResolution(Date cachedDate, Long currentDateResolution)
      Return the Date to be used in a query based on a cached Date and a resolution.

      This is meant to be used as a mechanism to allow caching to occur in queries that compare a date to now. Since caching will only occur if the query is exactly the same, you cannot use the exact current timestamp or the query will never be cached. This method will return the same timestamp for a Date until it has exceeded the resolution, at which point the current timestamp will be used.

      NOTE: This method will update the passed in cachedDate if the resolution has passed.

      Parameters:
      cachedDate - a Date that is cached, typically by a DAO, to be used in queries that involve date ranges. This object will be updated if the resolution has passed.
      currentDateResolution - resolution in milliseconds.
      Returns:
      the Date object to use in a query involving date ranges.