Skip to content

Commit

Permalink
Merge pull request #1759 from brenuart/gh1754
Browse files Browse the repository at this point in the history
Reuse Calendar instance during parsing
  • Loading branch information
cowtowncoder authored Sep 7, 2017
2 parents b308e29 + 28334b7 commit 8860630
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,7 @@ public StringBuffer format(Date date, StringBuffer toAppendTo,
protected void _format(TimeZone tz, Locale loc, Date date,
StringBuffer buffer)
{
Calendar cal = _calendar;
if (cal == null ) {
_calendar = cal = (Calendar)CALENDAR.clone();
}
if (!cal.getTimeZone().equals(tz) ) {
cal.setTimeZone(tz);
}
// Note: Calendar locale not updated since we don't need it here...
Calendar cal = _getCalendar(tz);
cal.setTime(date);

pad4(buffer, cal.get(Calendar.YEAR));
Expand Down Expand Up @@ -605,10 +598,7 @@ protected Date _parseAsISO8601(String dateStr, ParsePosition bogus)
if ((_timezone != null) && ('Z' != dateStr.charAt(totalLen-1))) {
tz = _timezone;
}
Calendar cal = new GregorianCalendar(tz, _locale);
if (_lenient != null) {
cal.setLenient(_lenient.booleanValue());
}
Calendar cal = _getCalendar(tz);
String formatStr;
if (totalLen <= 10) {
Matcher m = PATTERN_PLAIN.matcher(dateStr);
Expand Down Expand Up @@ -757,6 +747,20 @@ protected void _clearFormats() {
_formatRFC1123 = null;
}

protected Calendar _getCalendar(TimeZone tz) {
Calendar cal = _calendar;
if (cal == null ) {
_calendar = cal = (Calendar)CALENDAR.clone();
}
if (!cal.getTimeZone().equals(tz) ) {
cal.setTimeZone(tz);
}
cal.setLenient(isLenient());
cal.clear();

return cal;
}

protected static <T> boolean _equals(T value1, T value2) {
if (value1 == value2) {
return true;
Expand Down

0 comments on commit 8860630

Please sign in to comment.