Class DateFormatter

java.lang.Object
io.netty.handler.codec.DateFormatter

public final class DateFormatter extends Object
A formatter for HTTP header dates, such as "Expires" and "Date" headers, or "expires" field in "Set-Cookie". On the parsing side, it honors RFC6265 (so it supports RFC1123). Note that:
  • Day of week is ignored and not validated
  • Timezone is ignored, as RFC6265 assumes UTC
If you're looking for a date format that validates day of week, or supports other timezones, consider using java.util.DateTimeFormatter.RFC_1123_DATE_TIME. On the formatting side, it uses a subset of RFC1123 (2 digit day-of-month and 4 digit year) as per RFC2616. This subset supports RFC6265.
See Also:
  • Field Details

    • DELIMITERS

      private static final BitSet DELIMITERS
    • DAY_OF_WEEK_TO_SHORT_NAME

      private static final String[] DAY_OF_WEEK_TO_SHORT_NAME
    • CALENDAR_MONTH_TO_SHORT_NAME

      private static final String[] CALENDAR_MONTH_TO_SHORT_NAME
    • INSTANCES

      private static final FastThreadLocal<DateFormatter> INSTANCES
    • cal

      private final GregorianCalendar cal
    • sb

      private final StringBuilder sb
    • timeFound

      private boolean timeFound
    • hours

      private int hours
    • minutes

      private int minutes
    • seconds

      private int seconds
    • dayOfMonthFound

      private boolean dayOfMonthFound
    • dayOfMonth

      private int dayOfMonth
    • monthFound

      private boolean monthFound
    • month

      private int month
    • yearFound

      private boolean yearFound
    • year

      private int year
  • Constructor Details

    • DateFormatter

      private DateFormatter()
  • Method Details

    • parseHttpDate

      public static Date parseHttpDate(CharSequence txt)
      Parse some text into a Date, according to RFC6265
      Parameters:
      txt - text to parse
      Returns:
      a Date, or null if text couldn't be parsed
    • parseHttpDate

      public static Date parseHttpDate(CharSequence txt, int start, int end)
      Parse some text into a Date, according to RFC6265
      Parameters:
      txt - text to parse
      start - the start index inside txt
      end - the end index inside txt
      Returns:
      a Date, or null if text couldn't be parsed
    • format

      public static String format(Date date)
      Format a Date into RFC1123 format
      Parameters:
      date - the date to format
      Returns:
      a RFC1123 string
    • append

      public static StringBuilder append(Date date, StringBuilder sb)
      Append a Date to a StringBuilder into RFC1123 format
      Parameters:
      date - the date to format
      sb - the StringBuilder
      Returns:
      the same StringBuilder
    • formatter

      private static DateFormatter formatter()
    • isDelim

      private static boolean isDelim(char c)
    • isDigit

      private static boolean isDigit(char c)
    • getNumericalValue

      private static int getNumericalValue(char c)
    • reset

      public void reset()
    • tryParseTime

      private boolean tryParseTime(CharSequence txt, int tokenStart, int tokenEnd)
    • tryParseDayOfMonth

      private boolean tryParseDayOfMonth(CharSequence txt, int tokenStart, int tokenEnd)
    • tryParseMonth

      private boolean tryParseMonth(CharSequence txt, int tokenStart, int tokenEnd)
    • tryParseYear

      private boolean tryParseYear(CharSequence txt, int tokenStart, int tokenEnd)
    • parseToken

      private boolean parseToken(CharSequence txt, int tokenStart, int tokenEnd)
    • parse0

      private Date parse0(CharSequence txt, int start, int end)
    • parse1

      private boolean parse1(CharSequence txt, int start, int end)
    • normalizeAndValidate

      private boolean normalizeAndValidate()
    • computeDate

      private Date computeDate()
    • format0

      private String format0(Date date)
    • append0

      private StringBuilder append0(Date date, StringBuilder sb)
    • appendZeroLeftPadded

      private static StringBuilder appendZeroLeftPadded(int value, StringBuilder sb)