Class DateTimeHelper


  • public final class DateTimeHelper
    extends Object
    Utility class for Time formatting and parsing. Uses Joda Time.
    Since:
    1.0.0
    • Method Detail

      • parseIsoString2DateTime

        public static org.joda.time.DateTime parseIsoString2DateTime​(String timeString)
                                                              throws DateTimeParseException
        Parses a time String to a Joda Time DateTime object
        Parameters:
        timeString - Time String
        Returns:
        DateTime object
        Throws:
        DateTimeParseException - If an error occurs.
      • formatDateTime2IsoString

        public static String formatDateTime2IsoString​(org.joda.time.DateTime dateTime)
        Formats a DateTime to a ISO-8601 String
        Parameters:
        dateTime - Time object
        Returns:
        ISO-8601 formatted time String
      • formatDateTime2ResponseString

        public static String formatDateTime2ResponseString​(org.joda.time.DateTime dateTime)
                                                    throws DateTimeFormatException
        Formats a DateTime to a String using the response format
        Parameters:
        dateTime - Time object
        Returns:
        Response formatted time String
        Throws:
        DateTimeFormatException - If an error occurs.
      • formatDateTime2FormattedString

        public static String formatDateTime2FormattedString​(org.joda.time.DateTime dateTime,
                                                            String dateFormat)
                                                     throws DateTimeFormatException
        Formats a DateTime to a String using specified format
        Parameters:
        dateTime - Time object
        dateFormat - the date time format
        Returns:
        Specified formatted time String
        Throws:
        DateTimeFormatException - If an error occurs.
      • formatDateTime2FormattedString

        public static String formatDateTime2FormattedString​(org.joda.time.DateTime dateTime,
                                                            org.joda.time.format.DateTimeFormatter formatter)
                                                     throws DateTimeFormatException
        Formats a DateTime to a DAte using specified DateTimeFormatter
        Parameters:
        dateTime - Time object
        formatter - the DateTimeFormatter
        Returns:
        Specified formatted time String
        Throws:
        DateTimeFormatException - If an error occurs.
      • formatDateTime2YearMonthDayDateStringYMD

        public static String formatDateTime2YearMonthDayDateStringYMD​(org.joda.time.DateTime dateTime)
        formats a DateTime to a string with year-month-day.
        Parameters:
        dateTime - The DateTime.
        Returns:
        Returns formatted time String.
        Throws:
        DateTimeFormatException - If an error occurs.
      • formatDateTime2YearMonthDateString

        public static String formatDateTime2YearMonthDateString​(org.joda.time.DateTime dateTime)
                                                         throws DateTimeFormatException
        formats a DateTime to a string with year-month.
        Parameters:
        dateTime - The DateTime.
        Returns:
        Returns formatted time String.
        Throws:
        DateTimeFormatException - If an error occurs.
      • formatDateTime2YearDateString

        public static String formatDateTime2YearDateString​(org.joda.time.DateTime dateTime)
                                                    throws DateTimeFormatException
        formats a DateTime to a string with year.
        Parameters:
        dateTime - The DateTime.
        Returns:
        Returns formatted time String.
        Throws:
        DateTimeFormatException - If an error occurs.
      • getTimeLengthBeforeTimeZone

        public static int getTimeLengthBeforeTimeZone​(String time)
      • setDateTime2EndOfMostPreciseUnit4RequestedEndPosition

        public static org.joda.time.DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition​(org.joda.time.DateTime dateTime,
                                                                                                   int isoTimeLength)
        Set the time object to the end values (seconds, minutes, hours, days,..) if the time Object has not all values
        Parameters:
        dateTime - Time object
        isoTimeLength - Length of the time object
        Returns:
        Modified time object.
      • parseDuration

        public static org.joda.time.Period parseDuration​(String duration)
        Parse a duration from a String representation
        Parameters:
        duration - Duration as String
        Returns:
        Period object of duration
      • calculateExpiresDateTime

        public static org.joda.time.DateTime calculateExpiresDateTime​(org.joda.time.DateTime start)
        Calculates the expire time for a time object
        Parameters:
        start - Time object
        Returns:
        Expire time
      • setResponseFormat

        public static void setResponseFormat​(String responseFormat)
        Set the response format
        Parameters:
        responseFormat - Defined response format
      • setLease

        public static void setLease​(int lease)
        Set the lease value
        Parameters:
        lease - Defined lease value
      • makeDateTime

        public static org.joda.time.DateTime makeDateTime​(Object object)
        Make a new UTC DateTime from an object
        Parameters:
        object - Object to make DateTime
        Returns:
        DateTime, or null if object was null
      • toUTC

        public static org.joda.time.DateTime toUTC​(org.joda.time.DateTime datetime)
        Transforms the supplied DateTime to UTC.
        Parameters:
        datetime - the date time (may be null)
        Returns:
        the UTC time (or null
      • max

        public static org.joda.time.DateTime max​(org.joda.time.DateTime dt1,
                                                 org.joda.time.DateTime dt2)
        Find the max of two dates (null safe)
        Parameters:
        dt1 - first DateTime
        dt2 - second DateTime
        Returns:
        Max of two dates
      • getDaysSince

        public static int getDaysSince​(org.joda.time.DateTime start,
                                       org.joda.time.DateTime end)
        Get days between the given DateTimes
        Parameters:
        start - Start DateTime
        end - End DateTime
        Returns:
        Days between the two DateTimes
      • getDaysSinceWithPrecision

        public static double getDaysSinceWithPrecision​(org.joda.time.DateTime start,
                                                       org.joda.time.DateTime end)
        Get days between the given DateTimes with precision
        Parameters:
        start - Start DateTime
        end - End DateTime
        Returns:
        Days with precisions between the two DateTimes
      • getMinutesSince

        public static int getMinutesSince​(org.joda.time.DateTime start,
                                          org.joda.time.DateTime end)
        Get minutes between the given DateTimes
        Parameters:
        start - Start DateTime
        end - End DateTime
        Returns:
        Minutes between the two DateTimes
      • getSecondsSinceEpoch

        public static double getSecondsSinceEpoch​(org.joda.time.DateTime time)
        Get seconds since epoch
        Parameters:
        time - DateTime to get seconds for
        Returns:
        Seconds since epoch