Class LocalDateTimeUtils


  • public class LocalDateTimeUtils
    extends Object
    Utility functions to manipulate LocalDateTime.
    • Constructor Detail

      • LocalDateTimeUtils

        public LocalDateTimeUtils()
    • Method Detail

      • min

        public static LocalDateTime min​(LocalDateTime t1,
                                        LocalDateTime t2)
        Returns the earlier of the two given time instances, or the first instance if two instances are equal.
        Parameters:
        t1 - the first time instance
        t2 - the second time instance
        Returns:
        the earlier time instance
      • max

        public static LocalDateTime max​(LocalDateTime t1,
                                        LocalDateTime t2)
        Returns the later of the two given time instances, or the first instance if two instances are equal.
        Parameters:
        t1 - the first time instance
        t2 - the second time instance
        Returns:
        the later time instance
      • isWeekend

        public static boolean isWeekend​(LocalDateTime time)
        Checks if the given time is a weekend.
        Parameters:
        time - a time
        Returns:
        true if the given time is a weekend
      • nextWeekDay

        public static LocalDateTime nextWeekDay​(LocalDateTime time)
        Gets the next weekday, i.e., skipping Saturdays and Sundays.
        Parameters:
        time - a LocalDateTime
        Returns:
        the next weekday
      • previousWeekDay

        public static LocalDateTime previousWeekDay​(LocalDateTime time)
        Gets the previous weekday, i.e., skipping Saturdays and Sundays.
        Parameters:
        time - a LocalDateTime
        Returns:
        the previous weekday
      • periodicInstants

        public static List<LocalDateTime> periodicInstants​(LocalDateTime startTime,
                                                           Period period,
                                                           int nPeriods)
        Generates a list of periodic time instants. The number of instants equals to the number of periods plus one.
        Parameters:
        startTime - the start time
        period - the period
        nPeriods - the number of periods
        Returns:
        a list of periodic time instants
      • periodicInstantsWithinInterval

        public static List<LocalDateTime> periodicInstantsWithinInterval​(LocalDateTimeInterval interval,
                                                                         Period period)
        Generates a list of periodic time instants within a given interval. That is, the first instant is the start of the interval, and the last instant is before the end of the interval.
        Parameters:
        interval - the interval
        period - the period
        Returns:
        a list of periodic time instants
      • periodicInstantsSpanningInterval

        public static List<LocalDateTime> periodicInstantsSpanningInterval​(LocalDateTimeInterval interval,
                                                                           Period period)
        Generates a list of periodic time instants which span the whole given interval. That is, the first instant is the start of the interval, and the last instant is after the end of the interval.
        Parameters:
        interval - the interval
        period - the period
        Returns:
        a list of periodic time instants
      • periodCountBetween

        public static long periodCountBetween​(LocalDateTime t1,
                                              LocalDateTime t2,
                                              Period period)
        Returns the number of whole periods between two time instants.
        Parameters:
        t1 - the first instant
        t2 - the second instant
        period - a period
        Returns:
        the number of periods between t1 and t2
      • comparePeriods

        public static int comparePeriods​(Period period1,
                                         Period period2)
        Compares two periods, assuming 30 days per month.
        Parameters:
        period1 - the first period
        period2 - the second period
        Returns:
        0 if two periods are of the same length; negative if the period is shorter; positive otherwise
      • comparePeriods

        public static int comparePeriods​(Period period1,
                                         Period period2,
                                         int nDaysPerMonth)
        Compares two periods, with the assumed number of days per month.
        Parameters:
        period1 - the first period
        period2 - the second period
        nDaysPerMonth - the assumed number of days per month
        Returns:
        0 if two periods are of the same length; negative if the period is shorter; positive otherwise
      • periodDayCount

        public static long periodDayCount​(Period period,
                                          int nDaysPerMonth)
        Estimates the number of days in a period, with the assumed number of days per month.
        Parameters:
        period - the period
        nDaysPerMonth - the assumed number of days per month
        Returns:
        the estimated day count
      • fixedSizeIntervals

        public static List<LocalDateTimeInterval> fixedSizeIntervals​(LocalDateTime start,
                                                                     LocalDateTime end,
                                                                     Period period)
        Creates a list of intervals between start and end every so often. Note that the last interval ends at the given end time, so it can be shorter than the given period.
        Parameters:
        start - the start time
        end - the end time
        period - the period or length of each interval
        Returns:
        a list of intervals