diff options
-rw-r--r-- | server/src/main/java/com/vaadin/data/converter/LocalDateTimeToDateConverter.java | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/server/src/main/java/com/vaadin/data/converter/LocalDateTimeToDateConverter.java b/server/src/main/java/com/vaadin/data/converter/LocalDateTimeToDateConverter.java index e5fa45a3fb..167c452eaf 100644 --- a/server/src/main/java/com/vaadin/data/converter/LocalDateTimeToDateConverter.java +++ b/server/src/main/java/com/vaadin/data/converter/LocalDateTimeToDateConverter.java @@ -17,7 +17,7 @@ package com.vaadin.data.converter; import java.time.Instant; import java.time.LocalDateTime; -import java.time.ZoneOffset; +import java.time.ZoneId; import java.util.Date; import java.util.Objects; @@ -35,41 +35,35 @@ import com.vaadin.ui.InlineDateTimeField; * @author Vaadin Ltd * @since 8.0 */ -public class LocalDateTimeToDateConverter - implements Converter<LocalDateTime, Date> { +public class LocalDateTimeToDateConverter implements Converter<LocalDateTime, Date> { - private ZoneOffset zoneOffset; + private ZoneId zoneId; /** * Creates a new converter using the given time zone. * - * @param zoneOffset - * the time zone offset to use, not <code>null</code> + * @param zoneId the time zone to use, not <code>null</code> */ - public LocalDateTimeToDateConverter(ZoneOffset zoneOffset) { - this.zoneOffset = Objects.requireNonNull(zoneOffset, - "Zone offset cannot be null"); + public LocalDateTimeToDateConverter(ZoneId zoneId) { + this.zoneId = Objects.requireNonNull(zoneId, "Zone identifier cannot be null"); } @Override - public Result<Date> convertToModel(LocalDateTime localDate, - ValueContext context) { + public Result<Date> convertToModel(LocalDateTime localDate, ValueContext context) { if (localDate == null) { return Result.ok(null); } - return Result.ok(Date.from(localDate.toInstant(zoneOffset))); + return Result.ok(Date.from(localDate.atZone(zoneId).toInstant())); } @Override - public LocalDateTime convertToPresentation(Date date, - ValueContext context) { + public LocalDateTime convertToPresentation(Date date, ValueContext context) { if (date == null) { return null; } - return Instant.ofEpochMilli(date.getTime()).atZone(zoneOffset) - .toLocalDateTime(); + return Instant.ofEpochMilli(date.getTime()).atZone(zoneId).toLocalDateTime(); } } |