fr.fezlight.eventsystem.converters.ZonedDateTimeConverters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-starter-event-system-mongodb Show documentation
Show all versions of spring-boot-starter-event-system-mongodb Show documentation
This module is the MongoDB implementation for event system based on Spring Modulith MongoDB.
The newest version!
package fr.fezlight.eventsystem.converters;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Date;
/**
* Class used to convert {@link ZonedDateTime} object into MongoDB.
*
* @author FezLight
*/
public class ZonedDateTimeConverters {
@ReadingConverter
public static class ZonedDateTimeReadConverter implements Converter {
@Override
public ZonedDateTime convert(Date source) {
return source.toInstant().atZone(ZoneOffset.UTC);
}
}
@WritingConverter
public static class ZonedDateTimeWriteConverter implements Converter {
@Override
public Date convert(ZonedDateTime source) {
return Date.from(source.toInstant());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy