/** * Override this method in derived tests to change the construction of instances * @param format the format string to use * @param timeZone the time zone to use * @param locale the locale to use * @return the DatePrinter to use for testing */ protected DatePrinter getInstance(final String format, final TimeZone timeZone, final Locale locale) { return new FastDatePrinter(format, timeZone, locale); }
/** * <p>Formats a {@code Calendar} object.</p> * * @param calendar the calendar to format * @return the formatted string */ @Override public String format(final Calendar calendar) { return printer.format(calendar); }
@Override public StringBuffer format(final Date date, final StringBuffer buf) { final Calendar c = newCalendar(); c.setTime(date); return (StringBuffer) applyRules(c, (Appendable)buf); }
/** * <p>Gets a debugging string version of this formatter.</p> * * @return a debugging string */ @Override public String toString() { return "FastDateFormat[" + printer.getPattern() + "," + printer.getLocale() + "," + printer.getTimeZone().getID() + "]"; }
@Override public String format(final Date date) { final Calendar c = newCalendar(); c.setTime(date); return applyRulesToString(c); }
@Test public void testPrinter() { final FastDatePrinter printer = new FastDatePrinter("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault()); vulgar.setMinimalDaysInFirstWeek(4); vulgar.setFirstDayOfWeek(Calendar.MONDAY); assertEquals(isoForm, printer.format(vulgar)); } }
/** * Performs the formatting by applying the rules to the * specified calendar. * * @param calendar the calendar to format * @param buf the buffer to format into * @return the specified string buffer * * @deprecated use {@link #format(Calendar)} or {@link #format(Calendar, Appendable)} */ @Deprecated protected StringBuffer applyRules(final Calendar calendar, final StringBuffer buf) { return (StringBuffer) applyRules(calendar, (Appendable)buf); }
/** * Constructs an instance of {@code TimeZoneNameRule} with the specified properties. * * @param timeZone the time zone * @param locale the locale * @param style the style */ TimeZoneNameRule(final TimeZone timeZone, final Locale locale, final int style) { mLocale = locale; mStyle = style; mStandard = getTimeZoneDisplay(timeZone, false, style, locale); mDaylight = getTimeZoneDisplay(timeZone, true, style, locale); }
/** * <p>Gets the pattern used by this formatter.</p> * * @return the pattern, {@link java.text.SimpleDateFormat} compatible */ @Override public String getPattern() { return printer.getPattern(); }
/** * <p>Gets the time zone used by this formatter.</p> * * <p>This zone is always used for {@code Date} formatting. </p> * * @return the time zone */ @Override public TimeZone getTimeZone() { return printer.getTimeZone(); }
/** * <p>Gets the locale used by this formatter.</p> * * @return the locale */ @Override public Locale getLocale() { return printer.getLocale(); }
/** * <p>Gets an estimate for the maximum string length that the * formatter will produce.</p> * * <p>The actual formatted length will almost always be less than or * equal to this amount.</p> * * @return the maximum formatted length */ public int getMaxLengthEstimate() { return printer.getMaxLengthEstimate(); }
/** * <p>Compares two objects for equality.</p> * * @param obj the object to compare to * @return {@code true} if equal */ @Override public boolean equals(final Object obj) { if (!(obj instanceof FastDateFormat)) { return false; } final FastDateFormat other = (FastDateFormat) obj; // no need to check parser, as it has same invariants as printer return printer.equals(other.printer); }
/** * <p>Gets a debugging string version of this formatter.</p> * * @return a debugging string */ @Override public String toString() { return "FastDateFormat[" + printer.getPattern() + "," + printer.getLocale() + "," + printer.getTimeZone().getID() + "]"; }
@Override public String format(final long millis) { final Calendar c = newCalendar(); c.setTimeInMillis(millis); return applyRulesToString(c); }
/** * <p>Performs the formatting by applying the rules to the * specified calendar.</p> * * @param calendar the calendar to format * @param buf the buffer to format into * @return the specified string buffer * @deprecated Use {@link #format(Calendar, Appendable)} */ @Deprecated protected StringBuffer applyRules(final Calendar calendar, final StringBuffer buf) { return printer.applyRules(calendar, buf); } }
/** * {@inheritDoc} */ @Override public void appendTo(final Appendable buffer, final Calendar calendar) throws IOException { final TimeZone zone = calendar.getTimeZone(); if (calendar.get(Calendar.DST_OFFSET) == 0) { buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale)); } else { buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale)); } } }
/** * <p>Gets the pattern used by this formatter.</p> * * @return the pattern, {@link java.text.SimpleDateFormat} compatible */ @Override public String getPattern() { return printer.getPattern(); }
/** * <p>Gets the time zone used by this formatter.</p> * * <p>This zone is always used for {@code Date} formatting. </p> * * @return the time zone */ @Override public TimeZone getTimeZone() { return printer.getTimeZone(); }
/** * <p>Gets the locale used by this formatter.</p> * * @return the locale */ @Override public Locale getLocale() { return printer.getLocale(); }