Created
June 13, 2012 14:49
-
-
Save oehme/2924543 to your computer and use it in GitHub Desktop.
Localizing Joda Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocalizingWrapper extends BeansWrapper { | |
private Provider<Locale> localeProvider; | |
public LocalizingWrapper(Provider<Locale> localeProvider) { | |
this.localeProvider = localeProvider; | |
} | |
@Override | |
public TemplateModel wrap(Object object) throws TemplateModelException { | |
if (object instanceof ReadableInstant) { | |
return new JodaInstantModel((ReadableInstant) object,localeProvider.get(), this); | |
} | |
if (object instanceof LocalDateTime) { | |
return new LocalDateTimeModel((LocalDateTime) object, localeProvider.get(), this); | |
} | |
if (object instanceof LocalDate) { | |
return new LocalDateModel((LocalDate) object, localeProvider.get(), this); | |
} | |
if (object instanceof LocalTime) { | |
return new LocalTimeModel((LocalTime) object, localeProvider.get(), this); | |
} | |
if (object instanceof YearMonth) { | |
return new YearMonthModel((YearMonth) object, this); | |
} | |
return super.wrap(object); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment