public class ChronoUnitUtils extends Object
ChronoUnit
.Constructor and Description |
---|
ChronoUnitUtils() |
Modifier and Type | Method and Description |
---|---|
static LocalTime |
truncate(LocalTime time,
ChronoUnit unit,
int stepRate)
Truncates the given time for the given chrono unit.
|
static ZonedDateTime |
truncate(ZonedDateTime time,
ChronoUnit unit,
int stepRate,
DayOfWeek firstDayOfWeek)
Truncates the given time for the given chrono unit.
|
public static ZonedDateTime truncate(ZonedDateTime time, ChronoUnit unit, int stepRate, DayOfWeek firstDayOfWeek)
ZonedDateTime.truncatedTo(java.time.temporal.TemporalUnit)
is not
sufficient as it only works for small units (hours, minutes, seconds). It
does not work for any unit that has a variable duration (a month can be
28, 30, or 31 days long). We also want to be able to support a
"step rate" (e.g. "truncate to minutes, to 5 minutes, to 15 minutes").time
- the time to truncateunit
- the chrono unit on which the truncation will be basedstepRate
- the step rate (1, 5, 15, ....)firstDayOfWeek
- the first day of the week, needed for truncating weekspublic static LocalTime truncate(LocalTime time, ChronoUnit unit, int stepRate)
ZonedDateTime.truncatedTo(java.time.temporal.TemporalUnit)
is not
sufficient as it only works for small units (hours, minutes, seconds). It
does not work for any unit that has a variable duration (a month can be
28, 30, or 31 days long). We also want to be able to support a
"step rate" (e.g. "truncate to minutes, to 5 minutes, to 15 minutes").time
- the time to truncateunit
- the chrono unit on which the truncation will be basedstepRate
- the step rate (1, 5, 15, ....)Copyright © 2020 Dirk Lemmermann Software & Consulting. All rights reserved.