- java.lang.Object
-
- com.flexganttfx.model.util.ChronoUnitUtils
-
public class ChronoUnitUtils extends Object
A utility class providing methods used in combination withChronoUnit
.
-
-
Constructor Summary
Constructors Constructor Description ChronoUnitUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Method Detail
-
truncate
public static ZonedDateTime truncate(ZonedDateTime time, ChronoUnit unit, int stepRate, DayOfWeek firstDayOfWeek)
Truncates the given time for the given chrono unit. The methodZonedDateTime.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").- Parameters:
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 weeks- Returns:
- the truncated time
-
truncate
public static LocalTime truncate(LocalTime time, ChronoUnit unit, int stepRate)
Truncates the given time for the given chrono unit. The methodZonedDateTime.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").- Parameters:
time
- the time to truncateunit
- the chrono unit on which the truncation will be basedstepRate
- the step rate (1, 5, 15, ....)- Returns:
- the truncated time
-
-