
com.peterphi.std.guice.restclient.converter.LocalDateStringConverter Maven / Gradle / Ivy
package com.peterphi.std.guice.restclient.converter;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.Provider;
@Provider
class LocalDateStringConverter implements ParamConverter
{
private static final DateTimeFormatter PARSER = ISODateTimeFormat.localDateParser();
private static final DateTimeFormatter FORMATTER = ISODateTimeFormat.date();
@Override
public LocalDate fromString(final String str)
{
if (str == null)
return null;
else if (str.equalsIgnoreCase("today"))
return new LocalDate();
else
return PARSER.parseLocalDate(str);
}
@Override
public String toString(final LocalDate value)
{
if (value == null)
return null;
else
return FORMATTER.print(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy