Package org.ametys.core.util.date
Class AdaptableDate
- java.lang.Object
-
- org.ametys.core.util.date.AdaptableDate
-
public final class AdaptableDate extends Object
This represents an advancedLocalDateTime
, allowing to be a static one, or a relative one to the moment theresolveDateTime()
method is called.
A single instance ofAdaptableDate
can beresolved
mutliple times, without being a problem at all, it just can lead to different results.
You can get anAdaptableDate
with:fromDateTime(java.time.LocalDateTime)
to have a static one, always resolved as the same givenLocalDateTime
fromDate(java.time.LocalDate)
to have a static one, always resolved as the same givenLocalDate
(at the start of the day)-
now()
to have one resolved as the currentLocalDateTime
whenresolveDateTime()
is called -
future(long, java.time.temporal.TemporalUnit)
to have one resolved with the given amount of givenTemporalUnit
added to the currentLocalDateTime
whenresolveDateTime()
is called -
past(long, java.time.temporal.TemporalUnit)
to have one resolved with the given amount of givenTemporalUnit
subtracted to the currentLocalDateTime
whenresolveDateTime()
is called
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AdaptableDate.AdaptableDateType
private static class
AdaptableDate.OffsetType
-
Field Summary
Fields Modifier and Type Field Description private static AdaptableDate
__NOW
private long
_relativeAmount
private AdaptableDate.OffsetType
_relativeOffsetType
private TemporalUnit
_relativeUnit
private LocalDateTime
_staticValue
private AdaptableDate.AdaptableDateType
_type
-
Constructor Summary
Constructors Modifier Constructor Description private
AdaptableDate(LocalDateTime date)
private
AdaptableDate(AdaptableDate.OffsetType offsetType, long amount, TemporalUnit unit)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AdaptableDate
fromDate(LocalDate date)
Gets a staticAdaptableDate
, always resolved as the givenLocalDate
static AdaptableDate
fromDateTime(LocalDateTime dateTime)
Gets a staticAdaptableDate
, always resolved as the givenLocalDateTime
static AdaptableDate
future(long amount, TemporalUnit unit)
Gets anAdaptableDate
, resolved as the currentLocalDateTime
at the moment of thecall
, plus the given amount of the givenTemporalUnit
, so as to get aLocalDateTime
in the futurestatic AdaptableDate
now()
static AdaptableDate
past(long amount, TemporalUnit unit)
Gets anAdaptableDate
, resolved as the currentLocalDateTime
at the moment of thecall
, minus the given amount of the givenTemporalUnit
, so as to get aLocalDateTime
in the pastLocalDate
resolveDate()
Resolves thisAdaptableDate
LocalDateTime
resolveDateTime()
Resolves thisAdaptableDate
String
toString()
-
-
-
Field Detail
-
__NOW
private static final AdaptableDate __NOW
-
_type
private final AdaptableDate.AdaptableDateType _type
-
_staticValue
private final LocalDateTime _staticValue
-
_relativeUnit
private final TemporalUnit _relativeUnit
-
_relativeAmount
private final long _relativeAmount
-
_relativeOffsetType
private final AdaptableDate.OffsetType _relativeOffsetType
-
-
Constructor Detail
-
AdaptableDate
private AdaptableDate(LocalDateTime date)
-
AdaptableDate
private AdaptableDate(AdaptableDate.OffsetType offsetType, long amount, TemporalUnit unit)
-
-
Method Detail
-
fromDateTime
public static AdaptableDate fromDateTime(LocalDateTime dateTime)
Gets a staticAdaptableDate
, always resolved as the givenLocalDateTime
- Parameters:
dateTime
- TheLocalDateTime
- Returns:
- The
AdaptableDate
-
fromDate
public static AdaptableDate fromDate(LocalDate date)
Gets a staticAdaptableDate
, always resolved as the givenLocalDate
- Parameters:
date
- TheLocalDate
- Returns:
- The
AdaptableDate
-
now
public static AdaptableDate now()
- Returns:
- The
AdaptableDate
-
past
public static AdaptableDate past(long amount, TemporalUnit unit)
Gets anAdaptableDate
, resolved as the currentLocalDateTime
at the moment of thecall
, minus the given amount of the givenTemporalUnit
, so as to get aLocalDateTime
in the past- Parameters:
amount
- The amount to subtractunit
- TheTemporalUnit
of the amount to subtract- Returns:
- The
AdaptableDate
-
future
public static AdaptableDate future(long amount, TemporalUnit unit)
Gets anAdaptableDate
, resolved as the currentLocalDateTime
at the moment of thecall
, plus the given amount of the givenTemporalUnit
, so as to get aLocalDateTime
in the future- Parameters:
amount
- The amount to addunit
- TheTemporalUnit
of the amount to add- Returns:
- The
AdaptableDate
-
resolveDateTime
public LocalDateTime resolveDateTime()
Resolves thisAdaptableDate
- Returns:
- The resolved
LocalDateTime
-
resolveDate
public LocalDate resolveDate()
Resolves thisAdaptableDate
- Returns:
- The resolved
LocalDate
-
-