Class ChronoUnitUtils

java.lang.Object
com.flexganttfx.model.util.ChronoUnitUtils

public class ChronoUnitUtils
extends Object
A utility class providing methods used in combination with ChronoUnit.
  • Constructor Details

    • ChronoUnitUtils

      public ChronoUnitUtils()
  • Method Details

    • truncate

      public static ZonedDateTime truncate​(ZonedDateTime time, ChronoUnit unit, int stepRate, DayOfWeek firstDayOfWeek)
      Truncates the given time for the given chrono unit. The method 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").
      Parameters:
      time - the time to truncate
      unit - the chrono unit on which the truncation will be based
      stepRate - 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 method 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").
      Parameters:
      time - the time to truncate
      unit - the chrono unit on which the truncation will be based
      stepRate - the step rate (1, 5, 15, ....)
      Returns:
      the truncated time