Package org.fastnate.util
Class RelativeDate
java.lang.Object
java.util.Date
org.fastnate.util.RelativeDate
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe precision of a difference between a reference date and a date property.static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RelativeDate.PrecisionUsed for adding days to a reference date.static final RelativeDate.PrecisionUsed for adding hours to a reference date.static final RelativeDate.PrecisionUsed for adding milliseconds to a reference date.static final RelativeDate.PrecisionUsed for adding minutes to a reference date.static final RelativeDate.ReferenceDateRepresents the constant for writing the "now" function to SQL.private static final RelativeDate.Precision[]All known precisions, from the smallest to the biggest.private final RelativeDate.ReferenceDateThe date that is the base for this date.static final RelativeDate.PrecisionUsed for adding seconds to a reference date.private static final longstatic final RelativeDate.ReferenceDateRepresents the constant for writing the "today" function to SQL.static final RelativeDate.PrecisionUsed for adding weeks to a reference date.static final RelativeDate.PrecisionUsed for adding years to a reference date. -
Constructor Summary
ConstructorsConstructorDescriptionRelativeDate(long timeInMillis) Creates a new instance with the given millis as time.RelativeDate(RelativeDate.ReferenceDate referenceDate, long deltaInMillis) Creates a new instance with the given millis as time and the given reference date.RelativeDate(RelativeDate.ReferenceDate referenceDate, long delta, RelativeDate.Precision precision) Creates a new difference to a given reference date. -
Method Summary
Modifier and TypeMethodDescriptionlongThe difference of the time to thereferenceDate.Finds the highest possible unit of the difference between the reference date and this date.The date that is the base for this date.Methods inherited from class java.util.Date
after, before, clone, compareTo, equals, from, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toInstant, toLocaleString, toString, UTC
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
TODAY
Represents the constant for writing the "today" function to SQL. -
NOW
Represents the constant for writing the "now" function to SQL. -
MILLISECONDS
Used for adding milliseconds to a reference date. -
SECONDS
Used for adding seconds to a reference date. -
MINUTES
Used for adding minutes to a reference date. -
HOURS
Used for adding hours to a reference date. -
DAYS
Used for adding days to a reference date. -
WEEKS
Used for adding weeks to a reference date. -
YEARS
Used for adding years to a reference date. -
PRECISIONS
All known precisions, from the smallest to the biggest. -
referenceDate
The date that is the base for this date. Only the difference to this date is written to the SQL file.
-
-
Constructor Details
-
RelativeDate
public RelativeDate(long timeInMillis) Creates a new instance with the given millis as time. UsesNOWas reference date.- Parameters:
timeInMillis- the time in milliseconds. Only the difference toNOWis written to SQL
-
RelativeDate
Creates a new instance with the given millis as time and the given reference date.- Parameters:
referenceDate- the reference datedeltaInMillis- 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 datedelta- the difference to the reference dateprecision- the unit of the delta, one of the constants defined above
-
-
Method Details
-
getDifference
public long getDifference()The difference of the time to thereferenceDate.- Returns:
- the difference in milliseconds
-
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
The date that is the base for this date. Only the difference to this date is written to the SQL file.
-