Class KiwiInstants
Instant.
First, KiwiInstants adds convenience methods for adding and subtracting common time increments to
Instant objects in the form of plus<TemporalField> and minus<TemporalField> methods such
as plusMinutes(Instant, long) and minusDays(Instant, long).
The Instant class does not support all of the ChronoUnit values via the generic
Instant.plus(long, TemporalUnit) and Instant.minus(long, TemporalUnit) methods.
Specifically it only supports (as of this writing):
ChronoUnit.NANOSChronoUnit.MICROSChronoUnit.MILLISChronoUnit.SECONDSChronoUnit.MINUTESChronoUnit.HOURSChronoUnit.HALF_DAYSChronoUnit.DAYS
Instant does not support any of the other units larger than ChronoUnit.DAYS such as weeks,
months, years, etc. This class supports adding and subtracting months and years directly, as well as other units via
the plusUsingZDT(Instant, long, TemporalUnit) and minusUsingZDT(Instant, long, TemporalUnit)
methods.
Second, KiwiInstants supports adding and subtracting months and years by first converting the Instant
to a ZonedDateTime at ZoneOffset.UTC. For example plusMonths(Instant, long). For other
TemporalUnit values you can use the plusUsingZDT(Instant, long, TemporalUnit) and
minusUsingZDT(Instant, long, TemporalUnit) methods, which will work as long as ZonedDateTime
supports the provided TemporalUnit.
Third, KiwiInstants provides utilities to retrieve individual standard parts of an Instant (second,
minute, hour, day, month, year) using the various get<TemporalField> methods, for example
getHour(Instant).
-
Method Summary
Modifier and TypeMethodDescriptionstatic intgetDayOfMonth(Instant instant) Return the value of the day of the month frominstant.static intReturn the value of the hour frominstant.static intReturn the value of the minute frominstant.static MonthReturn theMonthfrominstant.static intgetMonthValue(Instant instant) Return the value of the month (1-12) frominstant.static intReturn the value of the second frominstant.static intReturn the value of the year frominstant.static Instantstatic InstantminusHours(Instant instant, long hours) static InstantminusMinutes(Instant instant, long minutes) static InstantminusMonths(Instant instant, long months) static InstantminusUsingZDT(Instant instant, long amountToSubtract, TemporalUnit unit) Subtract any givenamountToSubtractof typeTemporalUnitfrom the given instant.static InstantminusYears(Instant instant, long years) static Instantstatic Instantstatic InstantplusMinutes(Instant instant, long minutes) static InstantplusMonths(Instant instant, long months) static InstantplusUsingZDT(Instant instant, long amountToAdd, TemporalUnit unit) Add any givenamountToAddof typeTemporalUnitfrom the given instant.static Instant
-
Method Details
-
getSecond
Return the value of the second frominstant.- Parameters:
instant- theInstant- Returns:
- the value of the second
-
getMinute
Return the value of the minute frominstant.- Parameters:
instant- theInstant- Returns:
- the value of the minute
-
getHour
Return the value of the hour frominstant.- Parameters:
instant- theInstant- Returns:
- the value of the hour
-
getDayOfMonth
Return the value of the day of the month frominstant.- Parameters:
instant- theInstant- Returns:
- the value of the day of the month
-
getMonth
Return theMonthfrominstant. -
getMonthValue
Return the value of the month (1-12) frominstant.- Parameters:
instant- theInstant- Returns:
- the value the month, i.e. 1-12
-
getYear
Return the value of the year frominstant.- Parameters:
instant- theInstant- Returns:
- the value of the year
-
minusMinutes
-
minusHours
-
minusDays
-
minusMonths
- Parameters:
instant- theInstantmonths- the amount of time to go backward in months- Returns:
- a new
Instantappropriately adjusted - Implementation Note:
- uses
ZonedDateTime(atZoneOffset.UTC) to traverse by month
-
minusYears
- Parameters:
instant- theInstantyears- the amount of time to go backward in years- Returns:
- a new
Instantappropriately adjusted - Implementation Note:
- uses
ZonedDateTime(atZoneOffset.UTC) to traverse by month
-
minusUsingZDT
Subtract any givenamountToSubtractof typeTemporalUnitfrom the given instant. This first converts theInstantinto aZonedDateTimeatZoneOffset.UTCbefore applying the subtraction. -
plusMinutes
-
plusHours
-
plusDays
-
plusMonths
- Parameters:
instant- theInstantmonths- the amount of time to go forward in months- Returns:
- a new
Instantappropriately adjusted - Implementation Note:
- uses
ZonedDateTime(atZoneOffset.UTC) to traverse by month
-
plusYears
- Parameters:
instant- theInstantyears- the amount of time to go forward in years- Returns:
- a new
Instantappropriately adjusted - Implementation Note:
- uses
ZonedDateTime(atZoneOffset.UTC) to traverse by month
-
plusUsingZDT
Add any givenamountToAddof typeTemporalUnitfrom the given instant. This first converts theInstantinto aZonedDateTimeatZoneOffset.UTCbefore applying the addition.
-