Package com.ssgllc.fish.f.instant
Class F_Instant_Add
java.lang.Object
com.ssgllc.fish.f.instant.F_Instant_Add
Moment arithmetic, reached as
add or subtract on an F_Instant.
The direction comes from which field you went through, so counts stay positive. Note the split in behaviour: minutes, hours, days and weeks add fixed durations, while months and years are resolved as calendar shifts in a zone - which is why those two take an optional zone id.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondays(int days) Moves the moment by a number of days.hours(int hours) Moves the moment by a number of hours.minutes(int minutes) Moves the moment by a number of minutes.months(int months) Moves the moment by a number of months, in the system default zone.Moves the moment by a number of months, resolved in an explicit zone.weeks(int weeks) Moves the moment by a number of weeks.years(int years) Moves the moment by a number of years, in the system default zone.Moves the moment by a number of years, resolved in an explicit zone.
-
Constructor Details
-
F_Instant_Add
-
-
Method Details
-
minutes
Moves the moment by a number of minutes. Reached asaddto move forwards orsubtractto move backwards, so the count is always positive.- Parameters:
minutes- the number of minutes to move- Returns:
- the shifted moment, to continue the chain from
Groovy example:
f().instant.now().add.minutes(30).toIso()
Returns:
half an hour from now
SpEL example:
#f().instant.now().add.minutes(30).toIso()
-
hours
Moves the moment by a number of hours. Reached asaddto move forwards orsubtractto move backwards, so the count is always positive.- Parameters:
hours- the number of hours to move- Returns:
- the shifted moment, to continue the chain from
Groovy example:
f().instant.now().subtract.hours(2).toIso()
Returns:
two hours ago
SpEL example:
#f().instant.now().subtract.hours(2).toIso()
-
days
Moves the moment by a number of days. Reached asaddto move forwards orsubtractto move backwards, so the count is always positive. A day here is exactly 24 hours, so a shift across a daylight-saving boundary moves the local wall-clock time by an hour.- Parameters:
days- the number of days to move- Returns:
- the shifted moment, to continue the chain from
Groovy example:
f().instant.now().add.days(30).toIso()
Returns:
thirty days from now
SpEL example:
#f().instant.now().add.days(30).toIso()
-
weeks
Moves the moment by a number of weeks. Reached asaddto move forwards orsubtractto move backwards, so the count is always positive. A week here is exactly seven 24-hour days, with the same daylight-saving caveat as days.- Parameters:
weeks- the number of weeks to move- Returns:
- the shifted moment, to continue the chain from
Groovy example:
f().instant.now().subtract.weeks(2).toIso()
Returns:
a fortnight ago
SpEL example:
#f().instant.now().subtract.weeks(2).toIso()
-
months
Moves the moment by a number of months, in the system default zone. Calendar months are not a fixed length, so this converts to local date-time, shifts, and converts back - keeping the local wall-clock time rather than adding a fixed duration. Usemonths(int, String)to pin the zone.- Parameters:
months- the number of months to move- Returns:
- the shifted moment, to continue the chain from
Groovy example:
f().instant.now().add.months(6).toIso()
Returns:
six months from now
SpEL example:
#f().instant.now().add.months(6).toIso()
-
months
Moves the moment by a number of months, resolved in an explicit zone. Prefer this overmonths(int)wherever the answer must not depend on the server's zone.- Parameters:
months- the number of months to movetimeZone- the zone id to resolve the shift in- Returns:
- the shifted moment, to continue the chain from
Groovy example:
f().instant.of(entity.createdDate).add.months(1, "America/New_York").toIso()
Returns:
a calendar month later, as reckoned in New York
SpEL example:
#f().instant.of(entity.createdDate).add.months(1, "America/New_York").toIso()
-
years
Moves the moment by a number of years, in the system default zone. Resolved as a calendar shift, so 29 February becomes 28 February in a non-leap target year. Useyears(int, String)to pin the zone.- Parameters:
years- the number of years to move- Returns:
- the shifted moment, to continue the chain from
Groovy example:
f().instant.of(entity.birthDate).add.years(18).toIso()
Returns:
the eighteenth birthday
SpEL example:
#f().instant.of(entity.birthDate).add.years(18).toIso()
-
years
Moves the moment by a number of years, resolved in an explicit zone.- Parameters:
years- the number of years to movetimeZone- the zone id to resolve the shift in- Returns:
- the shifted moment, to continue the chain from
Groovy example:
f().instant.now().subtract.years(1, "UTC").toIso()
Returns:
a year ago, reckoned in UTC
SpEL example:
#f().instant.now().subtract.years(1, "UTC").toIso()
-