Class TimeUtils


  • public class TimeUtils
    extends java.lang.Object
    Time utilities.
    Author:
    cecco
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.time.format.DateTimeFormatter DATE_FORMATTER  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean checkTimeInRangeWithSkew​(java.util.Date timeToCheck, java.util.Date startDate, java.util.Date endDate, int skewInMinutes)
      Checks that a date falls in the interval allowing for a certain clock skew expressed in minutes.
      static java.util.Date parseDate​(java.lang.String date)
      Parses a date from string
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DATE_FORMATTER

        public static final java.time.format.DateTimeFormatter DATE_FORMATTER
    • Method Detail

      • checkTimeInRangeWithSkew

        public static boolean checkTimeInRangeWithSkew​(java.util.Date timeToCheck,
                                                       java.util.Date startDate,
                                                       java.util.Date endDate,
                                                       int skewInMinutes)
        Checks that a date falls in the interval allowing for a certain clock skew expressed in minutes. The interval defined by (startDate, endDate) is modified to be (startDate - skewInMinutes, endDate + skewInMinutes).
        Parameters:
        timeToCheck - the time to be checked
        startDate - the start date of the time range
        endDate - the end date of the time range
        skewInMinutes - the clock skew in minutes to take into account
        Returns:
        true, if the time is in the given range, false otherwise
        Throws:
        java.lang.IllegalArgumentException - if passed an illegal time range
      • parseDate

        public static java.util.Date parseDate​(java.lang.String date)
        Parses a date from string
        Parameters:
        date - the date string representation;
        Returns:
        the parsed date
        Throws:
        java.lang.NullPointerException - if date is null
        java.time.format.DateTimeParseException - if the date is in the wrong format