Example #1
0
  /**
   * Constructs a new FastDateParser.
   *
   * @param pattern non-null {@link java.text.SimpleDateFormat} compatible pattern
   * @param timeZone non-null time zone to use
   * @param locale non-null locale
   * @param centuryStart The start of the century for 2 digit year parsing
   * @since 3.3
   */
  protected FastDateParser(
      final String pattern, final TimeZone timeZone, final Locale locale, final Date centuryStart) {
    this.pattern = pattern;
    this.timeZone = timeZone;
    this.locale = locale;

    final Calendar definingCalendar = Calendar.getInstance(timeZone, locale);
    int centuryStartYear;
    if (centuryStart != null) {
      definingCalendar.setTime(centuryStart);
      centuryStartYear = definingCalendar.get(Calendar.YEAR);
    } else if (locale.equals(JAPANESE_IMPERIAL)) {
      centuryStartYear = 0;
    } else {
      // from 80 years ago to 20 years from now
      definingCalendar.setTime(new Date());
      centuryStartYear = definingCalendar.get(Calendar.YEAR) - 80;
    }
    century = centuryStartYear / 100 * 100;
    startYear = centuryStartYear - century;

    init(definingCalendar);
  }
Example #2
0
  /**
   * Create the object after serialization. This implementation reinitializes the transient
   * properties.
   *
   * @param in ObjectInputStream from which the object is being deserialized.
   * @throws IOException if there is an IO issue.
   * @throws ClassNotFoundException if a class cannot be found.
   */
  private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();

    final Calendar definingCalendar = Calendar.getInstance(timeZone, locale);
    init(definingCalendar);
  }