Skip to content

Commit

Permalink
Cache formatter with offset parsed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guido Medina authored and cowtowncoder committed Dec 20, 2020
1 parent bd09cb6 commit 6f8bfd5
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class JacksonJodaDateFormat extends JacksonJodaFormatBase

protected final DateTimeFormatter _formatter;

protected final DateTimeFormatter _formatterWithOffsetParsed;

protected final TimeZone _jdkTimezone;

protected transient DateTimeZone _jodaTimezone;
Expand All @@ -47,6 +49,7 @@ public JacksonJodaDateFormat(DateTimeFormatter defaultFormatter)
{
super();
_formatter = defaultFormatter;
_formatterWithOffsetParsed = _formatter.withOffsetParsed();
DateTimeZone tz = defaultFormatter.getZone();
_jdkTimezone = (tz == null) ? null : tz.toTimeZone();
_explicitTimezone = false;
Expand All @@ -59,6 +62,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base,
{
super(base, useTimestamp);
_formatter = base._formatter;
_formatterWithOffsetParsed = _formatter.withOffsetParsed();
_jdkTimezone = base._jdkTimezone;
_explicitTimezone = base._explicitTimezone;
_adjustToContextTZOverride = base._adjustToContextTZOverride;
Expand All @@ -70,6 +74,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base,
{
super(base);
_formatter = formatter;
_formatterWithOffsetParsed = _formatter.withOffsetParsed();
_jdkTimezone = base._jdkTimezone;
_explicitTimezone = base._explicitTimezone;
_adjustToContextTZOverride = base._adjustToContextTZOverride;
Expand All @@ -80,6 +85,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base, TimeZone jdkTimezone)
{
super(base, jdkTimezone);
_formatter = base._formatter.withZone(DateTimeZone.forTimeZone(jdkTimezone));
_formatterWithOffsetParsed = _formatter.withOffsetParsed();
_jdkTimezone = jdkTimezone;
_explicitTimezone = true;
_adjustToContextTZOverride = base._adjustToContextTZOverride;
Expand All @@ -90,6 +96,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base, Locale locale)
{
super(base, locale);
_formatter = base._formatter.withLocale(locale);
_formatterWithOffsetParsed = _formatter.withOffsetParsed();
_jdkTimezone = base._jdkTimezone;
_explicitTimezone = base._explicitTimezone;
_adjustToContextTZOverride = base._adjustToContextTZOverride;
Expand All @@ -104,6 +111,7 @@ protected JacksonJodaDateFormat(JacksonJodaDateFormat base,
{
super(base);
_formatter = base._formatter;
_formatterWithOffsetParsed = _formatter.withOffsetParsed();
_jdkTimezone = base._jdkTimezone;
_explicitTimezone = base._explicitTimezone;
_adjustToContextTZOverride = adjustToContextTZOverride;
Expand Down Expand Up @@ -255,20 +263,20 @@ public DateTimeFormatter createFormatterWithLocale(SerializerProvider ctxt)
public DateTimeFormatter createParser(DeserializationContext ctxt)
{
DateTimeFormatter formatter = _formatter;
if (!_explicitLocale) {
Locale loc = ctxt.getLocale();
if (loc != null && !loc.equals(_locale)) {
formatter = formatter.withLocale(loc);
}
}
if (!_explicitTimezone) {
if (shouldAdjustToContextTimeZone(ctxt)) {
TimeZone tz = ctxt.getTimeZone();
if (tz != null && !tz.equals(_jdkTimezone)) {
formatter = formatter.withZone(DateTimeZone.forTimeZone(tz));
}
} else {
formatter = formatter.withOffsetParsed();
formatter = _formatterWithOffsetParsed;
}
}
if (!_explicitLocale) {
Locale loc = ctxt.getLocale();
if (loc != null && !loc.equals(_locale)) {
formatter = formatter.withLocale(loc);
}
}
return formatter;
Expand Down

0 comments on commit 6f8bfd5

Please sign in to comment.