Class PDTWebDateHelper

java.lang.Object
com.helger.commons.datetime.PDTWebDateHelper

@Immutable public final class PDTWebDateHelper extends Object
A helper class that parses Dates out of Strings with date time in RFC822 and W3CDateTime formats plus the variants Atom (0.3) and RSS (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) specificators added to those formats.
It uses the JDK java.text.SimpleDateFormat class attempting the parse using a mask for each one of the possible formats.
Original work Copyright 2004 Sun Microsystems, Inc.
Author:
Alejandro Abdelnur (original; mainly the formatting masks), Philip Helger (major modification)
  • Field Details

  • Method Details

    • parseOffsetDateTimeUsingMask

      @Nullable public static OffsetDateTime parseOffsetDateTimeUsingMask(@Nonnull PDTMask<?>[] aMasks, @Nonnull @Nonempty String sDate)
      Parses a Date out of a string using an array of masks. It uses the masks in order until one of them succeeds or all fail.
      Parameters:
      aMasks - array of masks to use for parsing the string
      sDate - string to parse for a date.
      Returns:
      the Date represented by the given string using one of the given masks. It returns null if it was not possible to parse the the string with any of the masks.
    • parseZonedDateTimeUsingMask

      @Nullable public static ZonedDateTime parseZonedDateTimeUsingMask(@Nonnull PDTMask<?>[] aMasks, @Nonnull @Nonempty String sDate, @Nullable ZoneId aDTZ)
      Parses a Date out of a string using an array of masks. It uses the masks in order until one of them succeeds or all fail.
      Parameters:
      aMasks - array of masks to use for parsing the string
      sDate - string to parse for a date.
      aDTZ - The date/time zone to use. Optional.
      Returns:
      the Date represented by the given string using one of the given masks. It returns null if it was not possible to parse the the string with any of the masks.
    • extractDateTimeZone

      @Nonnull public static WithZoneId extractDateTimeZone(@Nonnull String sDate)
      Extract the time zone from the passed string. UTC and GMT are supported.
      Parameters:
      sDate - The date string.
      Returns:
      A non-null WithZoneId, where the remaining string to be parsed (never null) and and the extracted time zone (may be null) are contained.
    • getDateTimeFromRFC822

      @Nullable public static ZonedDateTime getDateTimeFromRFC822(@Nullable String sDate)
      Parses a Date out of a String with a date in RFC822 format.
      It parsers the following formats:
      • "EEE, dd MMM uuuu HH:mm:ss z"
      • "EEE, dd MMM uuuu HH:mm z"
      • "EEE, dd MMM uu HH:mm:ss z"
      • "EEE, dd MMM uu HH:mm z"
      • "dd MMM uuuu HH:mm:ss z"
      • "dd MMM uuuu HH:mm z"
      • "dd MMM uu HH:mm:ss z"
      • "dd MMM uu HH:mm z"

      Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.

      Parameters:
      sDate - string to parse for a date. May be null.
      Returns:
      the Date represented by the given RFC822 string. It returns null if it was not possible to parse the given string into a ZonedDateTime or if the passed String was null.
    • getDateTimeFromW3C

      @Nullable public static OffsetDateTime getDateTimeFromW3C(@Nullable String sDate)
      Parses a Date out of a String with a date in W3C date-time format.
      It parsers the following formats:
      • "uuuu-MM-dd'T'HH:mm:ssz"
      • "uuuu-MM-dd'T'HH:mmz"
      • "uuuu-MM-dd"
      • "uuuu-MM"
      • "uuuu"

      Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.

      Parameters:
      sDate - string to parse for a date. May be null.
      Returns:
      the Date represented by the given W3C date-time string. It returns null if it was not possible to parse the given string into a ZonedDateTime or if the input string was null.
    • getDateTimeFromW3COrRFC822

      @Nullable public static ZonedDateTime getDateTimeFromW3COrRFC822(@Nullable String sDate)
      Parses a Date out of a String with a date in W3C date-time format or in a RFC822 format.
      Parameters:
      sDate - string to parse for a date.
      Returns:
      the Date represented by the given W3C date-time string. It returns null if it was not possible to parse the given string into a Date.
    • getLocalDateTimeFromW3COrRFC822

      @Nullable public static LocalDateTime getLocalDateTimeFromW3COrRFC822(@Nullable String sDate)
      Parses a Date out of a String with a date in W3C date-time format or in a RFC822 format.
      Parameters:
      sDate - string to parse for a date.
      Returns:
      the Date represented by the given W3C date-time string. It returns null if it was not possible to parse the given string into a Date.
    • getAsStringRFC822

      @Nullable public static String getAsStringRFC822(@Nullable ZonedDateTime aDateTime)
      create a RFC822 representation of a date.
      Parameters:
      aDateTime - Date to print. May be null.
      Returns:
      the RFC822 represented by the given Date. null if the parameter is null.
    • getAsStringRFC822

      @Nullable public static String getAsStringRFC822(@Nullable OffsetDateTime aDateTime)
      create a RFC822 representation of a date.
      Parameters:
      aDateTime - Date to print. May be null.
      Returns:
      the RFC822 represented by the given Date. null if the parameter is null.
    • getAsStringRFC822

      @Nullable public static String getAsStringRFC822(@Nullable LocalDateTime aDateTime)
      create a RFC822 representation of a date time using UTC date time zone.
      Parameters:
      aDateTime - Date to print. May be null.
      Returns:
      the RFC822 represented by the given Date. null if the parameter is null.
    • getAsStringW3C

      @Nullable public static String getAsStringW3C(@Nullable ZonedDateTime aDateTime)
      create a W3C Date Time representation of a date time using UTC date time zone.
      Parameters:
      aDateTime - Date to print. May not be null.
      Returns:
      the W3C Date Time represented by the given Date.
    • getAsStringW3C

      @Nullable public static String getAsStringW3C(@Nullable OffsetDateTime aDateTime)
      create a W3C Date Time representation of a date time using UTC date time zone.
      Parameters:
      aDateTime - Date to print. May not be null.
      Returns:
      the W3C Date Time represented by the given Date.
    • getAsStringW3C

      @Nullable public static String getAsStringW3C(@Nullable LocalDateTime aDateTime)
      create a W3C Date Time representation of a date.
      Parameters:
      aDateTime - Date to print. May not be null.
      Returns:
      the W3C Date Time represented by the given Date.
    • getCurrentDateTimeAsStringRFC822

      @Nonnull public static String getCurrentDateTimeAsStringRFC822()
      Returns:
      The current date time formatted using RFC 822
    • getCurrentDateTimeAsStringW3C

      @Nonnull public static String getCurrentDateTimeAsStringW3C()
      Returns:
      The current date time formatted using W3C format
    • getXSDFormatterDateTime

      @Nonnull public static DateTimeFormatter getXSDFormatterDateTime(@Nullable ZoneId aOverrideZoneID)
    • getLocalDateTimeFromXSD

      @Nullable public static LocalDateTime getLocalDateTimeFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable LocalDateTime aLDT)
    • getZonedDateTimeFromXSD

      @Nullable public static ZonedDateTime getZonedDateTimeFromXSD(@Nullable String sValue)
    • getZonedDateTimeFromXSD

      @Nullable public static ZonedDateTime getZonedDateTimeFromXSD(@Nullable String sValue, @Nullable ZoneId aZoneID)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable ZonedDateTime aZDT)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nonnull ZoneId aZoneID, @Nullable ZonedDateTime aZDT)
    • getOffsetDateTimeFromXSD

      @Nullable public static OffsetDateTime getOffsetDateTimeFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable OffsetDateTime aODT)
    • getXMLOffsetDateTimeFromXSD

      @Nullable public static XMLOffsetDateTime getXMLOffsetDateTimeFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable XMLOffsetDateTime aODT)
    • getXSDFormatterDate

      @Nonnull public static DateTimeFormatter getXSDFormatterDate()
    • getLocalDateFromXSD

      @Nullable public static LocalDate getLocalDateFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable LocalDate aLD)
    • getOffsetDateFromXSD

      @Nullable public static OffsetDate getOffsetDateFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable OffsetDate aOD)
    • getXMLOffsetDateFromXSD

      @Nullable public static XMLOffsetDate getXMLOffsetDateFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable XMLOffsetDate aOD)
    • getXSDFormatterTime

      @Nonnull public static DateTimeFormatter getXSDFormatterTime()
    • getLocalTimeFromXSD

      @Nullable public static LocalTime getLocalTimeFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable LocalTime aLT)
    • getOffsetTimeFromXSD

      @Nullable public static OffsetTime getOffsetTimeFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable OffsetTime aOT)
    • getXMLOffsetTimeFromXSD

      @Nullable public static XMLOffsetTime getXMLOffsetTimeFromXSD(@Nullable String sValue)
    • getAsStringXSD

      @Nullable public static String getAsStringXSD(@Nullable XMLOffsetTime aOT)