Class FastDatePrinter.EraField

java.lang.Object
org.apache.commons.lang3.time.FastDatePrinter.EraField
All Implemented Interfaces:
FastDatePrinter.Rule
Enclosing class:
FastDatePrinter

private static final class FastDatePrinter.EraField extends Object implements FastDatePrinter.Rule
Inner class to output the era name of the calendar being formatted.

DateFormatSymbols.getEras() only knows the two Gregorian eras. A locale whose default calendar is not Gregorian, like the Thai Buddhist or Japanese Imperial calendar, prints that calendar's year, so the era names have to come from that calendar as well, as SimpleDateFormat and FastDateParser do. The Japanese Imperial calendar also has more than two eras, so indexing the Gregorian names by its era value would throw an ArrayIndexOutOfBoundsException.

FastDatePrinter.format(Calendar) applies the rules to the caller's calendar, which need not be of the type the locale defaults to. An era value only has a meaning in the calendar it comes from, so the names are picked by the type of the calendar being formatted.

  • Field Details

    • GREGORY

      private static final String GREGORY
      The calendar type of a Gregorian calendar.
      See Also:
    • calendarType

      private final String calendarType
    • values

      private final String[] values
    • gregorianValues

      private final String[] gregorianValues
    • style

      private final int style
    • locale

      private final Locale locale
  • Constructor Details

  • Method Details

    • appendTo

      public void appendTo(Appendable buffer, Calendar calendar) throws IOException
      Appends the value of the specified calendar to the output buffer based on the rule implementation.
      Specified by:
      appendTo in interface FastDatePrinter.Rule
      Parameters:
      buffer - The output buffer.
      calendar - calendar to be appended.
      Throws:
      IOException - Thrown if an I/O error occurs.
    • estimateLength

      public int estimateLength()
      Returns the estimated length of the result.
      Specified by:
      estimateLength in interface FastDatePrinter.Rule
      Returns:
      The estimated length of the result.