Class DateRange

java.lang.Object
org.deltava.beans.DateRange
All Implemented Interfaces:
Serializable, Comparable<DateRange>, ComboAlias

public class DateRange extends Object implements Serializable, Comparable<DateRange>, ComboAlias
A bean to store date/time ranges.
Since:
3.6
Version:
11.0
Author:
Luke
See Also:
  • Constructor Details

    • DateRange

      public DateRange(Instant startDate, Instant endDate)
      Creates a date range.
      Parameters:
      startDate - the start date/time
      endDate - the end date/time
  • Method Details

    • createWeek

      public static DateRange createWeek(ZonedDateTime zdt)
      Creates a date range for a specific week.
      Parameters:
      zdt - a date/time within that day
      Returns:
      a DateRange
    • createMonth

      public static DateRange createMonth(ZonedDateTime zdt)
      Creates a date range for a specific month.
      Parameters:
      zdt - a date/time within that month
      Returns:
      a DateRange
    • createYear

      public static DateRange createYear(ZonedDateTime zdt)
      Creates a date range for a specific year.
      Parameters:
      zdt - a date/time within that year
      Returns:
      a DateRange
    • parse

      public static DateRange parse(String alias)
      Parses a Date range combo alias.
      Parameters:
      alias - the alias
      Returns:
      a DateRange, or null if unparseable
      See Also:
    • getStartDate

      public Instant getStartDate()
      Returns the start of the range.
      Returns:
      the start date/time
    • getEndDate

      public Instant getEndDate()
      Returns the end of the range.
      Returns:
      the end date/time
    • getLabel

      public String getLabel()
      Returns the range label.
      Returns:
      the label
    • contains

      public boolean contains(Instant dt)
      Returns whether a date/time is contained within this range.
      Parameters:
      dt - the date/time
      Returns:
      TRUE if contained, otherwise FALSE
    • getLength

      public long getLength()
      Returns the size of the range.
      Returns:
      the size in milliseconds
    • getComboName

      public String getComboName()
      Description copied from interface: ComboAlias
      Returns the visible name to use in the HTML <OPTION> element.
      Specified by:
      getComboName in interface ComboAlias
      Returns:
      The visible name for this entry
    • getComboAlias

      public String getComboAlias()
      Description copied from interface: ComboAlias
      Returns the alias to use in the HTML <OPTION> element.
      Specified by:
      getComboAlias in interface ComboAlias
      Returns:
      The alias for this entry
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(DateRange dr2)
      Compares two date ranges by comparing their start and end date/times.
      Specified by:
      compareTo in interface Comparable<DateRange>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object