Class RelativeDate

java.lang.Object
java.util.Date
org.fastnate.util.RelativeDate
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Date>

public class RelativeDate extends Date
Used for date calculation when writing entities. Examples:
Write "now" as property of a bean:
bean.setDate(RelativeDate.NOW)
Write "today" as property of a bean:
bean.setDate(RelativeDate.TODAY)
Write "yesterday" as property of a bean:
bean.setDate(new RelativeDate(RelativeDate.TODAY, - DateUtils.MILLIS_PER_DAY))
Author:
Tobias Liefke
See Also:
  • Field Details

  • Constructor Details

    • RelativeDate

      public RelativeDate(long timeInMillis)
      Creates a new instance with the given millis as time. Uses NOW as reference date.
      Parameters:
      timeInMillis - the time in milliseconds. Only the difference to NOW is written to SQL
    • RelativeDate

      public RelativeDate(RelativeDate.ReferenceDate referenceDate, long deltaInMillis)
      Creates a new instance with the given millis as time and the given reference date.
      Parameters:
      referenceDate - the reference date
      deltaInMillis - the difference to the reference date in milliseconds
    • RelativeDate

      public RelativeDate(RelativeDate.ReferenceDate referenceDate, long delta, RelativeDate.Precision precision)
      Creates a new difference to a given reference date.
      Parameters:
      referenceDate - the reference date
      delta - the difference to the reference date
      precision - the unit of the delta, one of the constants defined above
  • Method Details

    • getDifference

      public long getDifference()
      The difference of the time to the referenceDate.
      Returns:
      the difference in milliseconds
    • getPrecision

      public RelativeDate.Precision getPrecision()
      Finds the highest possible unit of the difference between the reference date and this date.
      Returns:
      the highest possible unit to use without loosing information
    • getReferenceDate

      public RelativeDate.ReferenceDate getReferenceDate()
      The date that is the base for this date. Only the difference to this date is written to the SQL file.