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

fr.fezlight.eventsystem.converters.ZonedDateTimeConverters Maven / Gradle / Ivy

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