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 ofAdaptableDatecan beresolvedmutliple times, without being a problem at all, it just can lead to different results.
You can get anAdaptableDatewith:fromDateTime(java.time.LocalDateTime)to have a static one, always resolved as the same givenLocalDateTimefromDate(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 currentLocalDateTimewhenresolveDateTime()is called -
future(long, java.time.temporal.TemporalUnit)to have one resolved with the given amount of givenTemporalUnitadded to the currentLocalDateTimewhenresolveDateTime()is called -
past(long, java.time.temporal.TemporalUnit)to have one resolved with the given amount of givenTemporalUnitsubtracted to the currentLocalDateTimewhenresolveDateTime()is called
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AdaptableDatefromDate(LocalDate date)Gets a staticAdaptableDate, always resolved as the givenLocalDatestatic AdaptableDatefromDateTime(LocalDateTime dateTime)Gets a staticAdaptableDate, always resolved as the givenLocalDateTimestatic AdaptableDatefuture(long amount, TemporalUnit unit)Gets anAdaptableDate, resolved as the currentLocalDateTimeat the moment of thecall, plus the given amount of the givenTemporalUnit, so as to get aLocalDateTimein the futurestatic AdaptableDatenow()static AdaptableDatepast(long amount, TemporalUnit unit)Gets anAdaptableDate, resolved as the currentLocalDateTimeat the moment of thecall, minus the given amount of the givenTemporalUnit, so as to get aLocalDateTimein the pastLocalDateresolveDate()Resolves thisAdaptableDateLocalDateTimeresolveDateTime()Resolves thisAdaptableDateStringtoString()
-
-
-
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 currentLocalDateTimeat the moment of thecall, minus the given amount of the givenTemporalUnit, so as to get aLocalDateTimein the past- Parameters:
amount- The amount to subtractunit- TheTemporalUnitof the amount to subtract- Returns:
- The
AdaptableDate
-
future
public static AdaptableDate future(long amount, TemporalUnit unit)
Gets anAdaptableDate, resolved as the currentLocalDateTimeat the moment of thecall, plus the given amount of the givenTemporalUnit, so as to get aLocalDateTimein the future- Parameters:
amount- The amount to addunit- TheTemporalUnitof 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
-
-