Skip to content

Commit 3939c0a

Browse files
committed
Clarify implementation with comment
Use final
1 parent 728e570 commit 3939c0a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,13 +1127,14 @@ public String format(final Calendar calendar) {
11271127
* @see org.apache.commons.lang3.time.DatePrinter#format(java.util.Calendar, Appendable)
11281128
*/
11291129
@Override
1130-
public <B extends Appendable> B format(Calendar calendar, final B buf) {
1131-
// do not pass in calendar directly, this will cause TimeZone of FastDatePrinter to be ignored
1130+
public <B extends Appendable> B format(final Calendar calendar, final B buf) {
1131+
// Don't edit the given Calendar, clone it only if needed.
1132+
Calendar actual = calendar;
11321133
if (!calendar.getTimeZone().equals(timeZone)) {
1133-
calendar = (Calendar) calendar.clone();
1134-
calendar.setTimeZone(timeZone);
1134+
actual = (Calendar) calendar.clone();
1135+
actual.setTimeZone(timeZone);
11351136
}
1136-
return applyRules(calendar, buf);
1137+
return applyRules(actual, buf);
11371138
}
11381139

11391140
/* (non-Javadoc)

0 commit comments

Comments
 (0)