All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.peterphi.std.guice.restclient.converter.LocalDateStringConverter Maven / Gradle / Ivy

There is a newer version: 9.2.0
Show newest version
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