generator.server.springboot.database.mongodb.main.JSR310DateConverters.mustache Maven / Gradle / Ivy
package {{packageName}}.wire.mongodb.infrastructure.secondary;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import org.springframework.core.convert.converter.Converter;
/**
* JSR310DateConverters class.
*/
public final class JSR310DateConverters {
private JSR310DateConverters() {}
@SuppressWarnings("java:S6548")
public static final class ZonedDateTimeToDateConverter implements Converter {
public static final ZonedDateTimeToDateConverter INSTANCE = new ZonedDateTimeToDateConverter();
private ZonedDateTimeToDateConverter() {}
@Override
public Date convert(ZonedDateTime source) {
return Date.from(source.toInstant());
}
}
@SuppressWarnings("java:S6548")
public static final class DateToZonedDateTimeConverter implements Converter {
public static final DateToZonedDateTimeConverter INSTANCE = new DateToZonedDateTimeConverter();
private DateToZonedDateTimeConverter() {}
@Override
public ZonedDateTime convert(Date source) {
return ZonedDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());
}
}
}