Class DateRange

java.lang.Object
com.webmethods.caf.faces.data.object.DateRange
All Implemented Interfaces:
Serializable

public class DateRange extends Object implements Serializable
Represents a period of time, optionally with regard to a fixed date. The period of time (the "range") may be a fixed number of milliseconds, a relative span ("today", "yesterday", etc.), or infinite (no start or end). If the period of time is a fixed positive number of milliseconds, the fixed date is the range's start. If the period of time is a fixed negative number of milliseconds, the fixed date is the range's end. If getFixedRange() is zero, getRelativeRange() is FIXED, and getDate() is null, the period of time is infinite, and the calculated start and end dates will be null. If getFixedRange() is Long.MAX_VALUE and getRelativeRange() is FIXED, then the period of time stretches from the specified date to the end of time. If getFixedRange() is Long.MIN_VALUE and getRelativeRange() is FIXED, then the period of time stretches from the beginning of time to the specified date.
See Also:
  • Field Details

  • Constructor Details

    • DateRange

      public DateRange()
      Creates a new (infinite) date range with a fixed length of zero and no fixed date.
    • DateRange

      public DateRange(long fixedRange)
      Creates a new date range with the specified fixed length and no fixed date.
      Parameters:
      fixedRange - Fixed range in milliseconds.
    • DateRange

      public DateRange(long fixedRange, Date date)
      Creates a new date range with the specified fixed length and date.
      Parameters:
      fixedRange - Fixed range in milliseconds.
      date - Fixed date. May be null (meaning no fixed date).
    • DateRange

      public DateRange(String relativeRange)
      Creates a new date range with the specified relative length. Must be either FIXED, THIS_DAY, PREVIOUS_DAY, THIS_WEEK, PREVIOUS_WEEK, THIS_MONTH, PREVIOUS_MONTH, THIS_YEAR, or PREVIOUS_YEAR. If fixedRange is not zero, this must be FIXED.
      Parameters:
      relativeRange - Relative range, an enumerated value.
  • Method Details

    • calculateStart

      public Date calculateStart()
      Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date) for the current user context. Takes in account the current user's calendar preferences.
      Returns:
      Calculated start date. BEGINNING_OF_TIME if no start date or range is infinite.
    • calculateStart

      public Date calculateStart(FacesContext context)
      Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date). Takes in account the current user's calendar preferences.
      Parameters:
      context - Current user context.
      Returns:
      Calculated start date. BEGINNING_OF_TIME if no start date or range is infinite.
    • calculateStart

      public Date calculateStart(FacesContext context, Calendar calendar)
      Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date). Takes in account the current user's calendar preferences.
      Parameters:
      context - Current user context.
      calendar - the calendar to use pre-initialized to the correct timezone
      Returns:
      Calculated start date. BEGINNING_OF_TIME if no start date or range is infinite.
    • calculateEnd

      public Date calculateEnd()
      Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date) for the current user context. Takes in account the current user's calendar preferences.
      Returns:
      Calculated end date. END_OF_TIME if no end date or range is infinite.
    • calculateEnd

      public Date calculateEnd(FacesContext context)
      Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date). Takes in account the current user's calendar preferences.
      Parameters:
      context - Current user context.
      Returns:
      Calculated end date. END_OF_TIME if no end date or range is infinite.
    • calculateEnd

      public Date calculateEnd(FacesContext context, Calendar calendar)
      Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date). Takes in account the current user's calendar preferences.
      Parameters:
      context - Current user context.
      calendar - the calendar to use pre-initialized to the correct timezone
      Returns:
      Calculated end date. END_OF_TIME if no end date or range is infinite.
    • getFixedRange

      public long getFixedRange()
      Fixed range in milliseconds. If relativeRange is not FIXED, this must be zero.
      Returns:
      Fixed range in milliseconds.
    • setFixedRange

      public void setFixedRange(long fixedRange)
      Fixed range in milliseconds. If relativeRange is not FIXED, this must be zero.
      Parameters:
      fixedRange - Fixed range in milliseconds.
    • getRelativeRange

      public String getRelativeRange()
      Relative range, an enumerated value. Must be either FIXED, THIS_DAY, PREVIOUS_DAY, THIS_WEEK, PREVIOUS_WEEK, THIS_MONTH, PREVIOUS_MONTH, THIS_YEAR, or PREVIOUS_YEAR. If fixedRange is not zero, this must be FIXED.
      Returns:
      Relative range, an enumerated value.
    • setRelativeRange

      public void setRelativeRange(String relativeRange)
      Relative range, an enumerated value. Must be either FIXED, THIS_DAY, PREVIOUS_DAY, THIS_WEEK, PREVIOUS_WEEK, THIS_MONTH, PREVIOUS_MONTH, THIS_YEAR, or PREVIOUS_YEAR. If fixedRange is not zero, this must be FIXED.
      Parameters:
      relativeRange - Relative range, an enumerated value.
    • getDate

      public Date getDate()
      Fixed date. May be null (meaning no fixed date). If relativeRange is FIXED, this is the range's end.
      Returns:
      Fixed date. May be null (meaning no fixed date).
    • setDate

      public void setDate(Date date)
      Fixed date. May be null (meaning no fixed date). If relativeRange is FIXED, this is the range's end.
      Parameters:
      Fixed - date. May be null (meaning no fixed date).
    • isSet

      public boolean isSet()
      Determine if this date range presents an actual date range is not empty
      Returns:
    • isEmpty

      public boolean isEmpty()
      Determine if this date range is empty and doesn't represent any actual date range
      Returns:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getControlCalendar

      protected Calendar getControlCalendar(FacesContext context)
    • setControlCalendar

      public void setControlCalendar(Calendar calendar)
      Set a calendar to be used for relative ranges. If no calendar is set, user's calendar will be used.
      Parameters:
      calendar - optional calendar to use in relative range calculations
    • main

      public static void main(String[] args)
    • assertTrue

      public static void assertTrue(String msg, boolean val)
    • assertFalse

      public static void assertFalse(String msg, boolean val)