Class TimeCalculations


  • public class TimeCalculations
    extends Object
    This class provides the means to incorporate local public holidays when doing time calculations.
    • Constructor Detail

      • TimeCalculations

        public TimeCalculations()
        Creates new time calculations based on the default locale of the JVM.
      • TimeCalculations

        public TimeCalculations​(Locale locale)
        Creates new time calculations based on the designated locale, that is the localised public holidays.
        Parameters:
        locale - The locale to use for the time calculations.
    • Method Detail

      • getWorkingDayAfter

        public Calendar getWorkingDayAfter​(Calendar fromDate,
                                           int workingDaysToAdd)
        Calculates the next working day when adding the designated amount of workdays to the designated date. The returned day will be a working day.
        Parameters:
        fromDate - The date to start the calculation.
        workingDaysToAdd - The amount of working days to add to the start date.
        Returns:
        The working day which is the designated amount of working days after the designated date.
      • timeLeft

        public static long timeLeft​(long startInNanos,
                                    long duration,
                                    TimeUnit unit)
        Gets the time in the designated unit that is left of the designated duration since the designated start. That is duration - (now - startInNanos) adjusted appropriately to the designated time unit.
        Parameters:
        startInNanos - The time in nanoseconds the waiting has started.
        duration - The time in the designated time unit, the waiting should take.
        unit - The unit of the duration and the calculated time left.
        Returns:
        The time left of the designated duration in the designated time unit. If this is 0 or a negative value, the duration has elapsed.