Fix timezone issue in DateTimeFormatterFactory

The DateTimeFormatterFactory introduced in SPR-7121 supports a timeZone
property; however, this property is currently not properly supported.

This commit addresses this issue by ensuring that the timeZone properly
is honored.

Issue: SPR-9953
This commit is contained in:
Sam Brannen
2012-11-04 18:59:01 +01:00
parent cef5f0222e
commit 93c01e0710
2 changed files with 31 additions and 8 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.util.StringUtils;
* or {@link #setStyle(String) style} (considered in that order).
*
* @author Phillip Webb
* @author Sam Brannen
* @see #getDateTimeFormatter()
* @see #getDateTimeFormatter(DateTimeFormatter)
* @since 3.2
@@ -100,7 +101,7 @@ public class DateTimeFormatterFactory implements FactoryBean<DateTimeFormatter>
public DateTimeFormatter getDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
DateTimeFormatter dateTimeFormatter = createDateTimeFormatter();
if(dateTimeFormatter != null && this.timeZone != null) {
dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
}
return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}