From 4f6abe2a9e1c8880d97c6230843bb65e6ddc2761 Mon Sep 17 00:00:00 2001 From: Masahiro Kitagawa Date: Mon, 11 Dec 2023 17:51:31 +0900 Subject: [PATCH] fix: Replace ZonedDateTime with LocalDateTime * Use UTC to calculate milli seconds from epoch --- .../com/lightcrafts/image/libs/LibRaw.java | 4 +- .../image/metadata/CIFFDirectory.java | 4 +- .../image/metadata/CoreDirectory.java | 8 +-- .../image/metadata/EXIFDirectory.java | 4 +- .../image/metadata/IPTCDirectory.java | 6 +- .../image/metadata/ImageMetadata.java | 6 +- .../image/metadata/TIFFDirectory.java | 4 +- .../metadata/makernotes/PentaxDirectory.java | 7 +-- .../providers/CaptureDateTimeProvider.java | 4 +- .../providers/FileDateTimeProvider.java | 4 +- .../image/metadata/values/DateMetaValue.java | 57 +++++++++++-------- .../image/types/RawImageCache.java | 3 +- .../utils/TerseLoggingHandler.java | 5 +- .../java/com/lightcrafts/utils/raw/DCRaw.java | 11 ++-- .../metadata/values/DateMetaValueTest.java | 25 ++++---- 15 files changed, 80 insertions(+), 72 deletions(-) diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/libs/LibRaw.java b/lightcrafts/src/main/java/com/lightcrafts/image/libs/LibRaw.java index f05fec01..38821b47 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/libs/LibRaw.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/libs/LibRaw.java @@ -216,11 +216,11 @@ public float getAperture() { } @Override - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { if (timestamp == 0) return null; // TODO: Is the libraw timestamp in UTC? - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC); + return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC); } public float getFocalLength() { diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/CIFFDirectory.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/CIFFDirectory.java index 70620e8e..425f71db 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/CIFFDirectory.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/CIFFDirectory.java @@ -2,7 +2,7 @@ package com.lightcrafts.image.metadata; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; import java.util.ResourceBundle; @@ -130,7 +130,7 @@ public String getCameraModel() { * {@inheritDoc} */ @Override - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { final ImageMetaValue value = getValue( CIFF_CAPTURED_TIME ); return value instanceof DateMetaValue ? ((DateMetaValue)value).getDateValue() : null; diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/CoreDirectory.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/CoreDirectory.java index 89a8aae4..661c5c34 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/CoreDirectory.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/CoreDirectory.java @@ -19,7 +19,7 @@ import java.awt.*; import java.awt.color.ICC_Profile; import java.io.File; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.*; import static com.lightcrafts.image.metadata.CoreTags.*; @@ -164,7 +164,7 @@ public String getCaption() { * {@inheritDoc} */ @Override - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { final ImageMetaValue value = getValue( CORE_CAPTURE_DATE_TIME ); return value instanceof DateMetaValue ? ((DateMetaValue)value).getDateValue() : null; @@ -192,7 +192,7 @@ public String getCopyright() { * {@inheritDoc} */ @Override - public ZonedDateTime getFileDateTime() { + public LocalDateTime getFileDateTime() { final ImageMetaValue value = getValue( CORE_FILE_DATE_TIME ); return value != null ? ((DateMetaValue)value).getDateValue() : null; } @@ -510,7 +510,7 @@ protected Collection toXMP( Document xmpDoc, String nsURI, ////////// MetadataDate & ModifyDate - final var now = ZonedDateTime.now(); + final var now = LocalDateTime.now(); final Element metadataDateElement = xmpDoc.createElementNS( XMP_XAP_NS, XMP_XAP_PREFIX + ":MetadataDate" ); diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/EXIFDirectory.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/EXIFDirectory.java index e704fae3..8c2e88db 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/EXIFDirectory.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/EXIFDirectory.java @@ -9,7 +9,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.*; import java.util.stream.Stream; @@ -107,7 +107,7 @@ public String getCaption() { * {@inheritDoc} */ @Override - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { ImageMetaValue value = getValue( EXIF_DATE_TIME_ORIGINAL ); if ( value == null ) value = getValue( EXIF_DATE_TIME_DIGITIZED ); diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/IPTCDirectory.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/IPTCDirectory.java index eee00fa5..27d936a4 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/IPTCDirectory.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/IPTCDirectory.java @@ -4,7 +4,7 @@ package com.lightcrafts.image.metadata; import java.io.UnsupportedEncodingException; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.*; import java.nio.ByteBuffer; @@ -73,7 +73,7 @@ public String getArtist() { * {@inheritDoc} */ @Override - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { final ImageMetaValue value = getValue( IPTC_DATE_CREATED ); return value instanceof DateMetaValue ? ((DateMetaValue)value).getDateValue() : null; @@ -638,7 +638,7 @@ private static void encodeTag( ByteBuffer buf, int tagID ) { * {@link DateMetaValue} plus the time. */ private ImageMetaValue mergeDateTime( ImageMetaValue date, int timeTagID ) { - // TODO: There might be a better way to do this with ZonedDateTime. + // TODO: There might be a better way to do this with LocalDateTime. final ImageMetaValue timeValue = getValue( timeTagID ); if ( timeValue == null ) diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/ImageMetadata.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/ImageMetadata.java index 47f47981..3eae1919 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/ImageMetadata.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/ImageMetadata.java @@ -18,7 +18,7 @@ import org.w3c.dom.Element; import java.io.*; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.*; import static com.lightcrafts.image.metadata.CoreTags.*; @@ -258,7 +258,7 @@ public String getCaption() { /** * {@inheritDoc} */ - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { final Collection dirs = findProvidersOf( CaptureDateTimeProvider.class ); for ( ImageMetadataDirectory dir : dirs ) { @@ -370,7 +370,7 @@ public File getFile() { * {@inheritDoc} */ @Override - public ZonedDateTime getFileDateTime() { + public LocalDateTime getFileDateTime() { final var dir = getDirectoryFor(CoreDirectory.class); return dir instanceof CoreDirectory ? ((CoreDirectory) dir).getFileDateTime() : null; diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/TIFFDirectory.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/TIFFDirectory.java index 28a6f056..4cbbdf6e 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/TIFFDirectory.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/TIFFDirectory.java @@ -16,7 +16,7 @@ import java.awt.image.RenderedImage; import java.io.IOException; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.*; import static com.lightcrafts.image.metadata.ImageMetaType.*; @@ -90,7 +90,7 @@ public String getCaption() { * {@inheritDoc} */ @Override - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { final ImageMetaValue value = getValue( TIFF_DATE_TIME ); return value instanceof DateMetaValue ? ((DateMetaValue)value).getDateValue() : null; diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/makernotes/PentaxDirectory.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/makernotes/PentaxDirectory.java index 5ce8a8a3..7e901763 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/makernotes/PentaxDirectory.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/makernotes/PentaxDirectory.java @@ -18,8 +18,7 @@ import java.awt.image.RenderedImage; import java.io.IOException; -import java.time.ZoneId; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.*; import java.util.regex.Pattern; @@ -55,7 +54,7 @@ public float getAperture() { * {@inheritDoc} */ @Override - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { final ImageMetaValue value = getValue( PENTAX_DATE ); return value instanceof DateMetaValue ? ((DateMetaValue)value).getDateValue() : null; @@ -283,7 +282,7 @@ public void putValue( Integer tagID, ImageMetaValue value ) { final int year = ((int)buf[0] & 0xFF) << 8 | (int)buf[1] & 0xFF; final int month = buf[2]; final int day = buf[3]; - final var dateTime = ZonedDateTime.of(year, month, day, 0, 0, 0, 0, ZoneId.systemDefault()); + final var dateTime = LocalDateTime.of(year, month, day, 0, 0, 0, 0); value = new DateMetaValue(dateTime); break; } diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/providers/CaptureDateTimeProvider.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/providers/CaptureDateTimeProvider.java index 069ab937..2b0b3201 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/providers/CaptureDateTimeProvider.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/providers/CaptureDateTimeProvider.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; /** * A CaptureDateTimeProvider provides the capture date/time of an @@ -22,7 +22,7 @@ public interface CaptureDateTimeProvider extends ImageMetadataProvider { * available. */ @Nullable - ZonedDateTime getCaptureDateTime(); + LocalDateTime getCaptureDateTime(); } /* vim:set et sw=4 ts=4: */ diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/providers/FileDateTimeProvider.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/providers/FileDateTimeProvider.java index 79eb5c53..e7904335 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/providers/FileDateTimeProvider.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/providers/FileDateTimeProvider.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; /** * A FileDateTimeProvider provides the last modified date/time of @@ -22,7 +22,7 @@ public interface FileDateTimeProvider extends ImageMetadataProvider { * available. */ @Nullable - ZonedDateTime getFileDateTime(); + LocalDateTime getFileDateTime(); } /* vim:set et sw=4 ts=4: */ diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/values/DateMetaValue.java b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/values/DateMetaValue.java index 7c106aba..66b7f407 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/metadata/values/DateMetaValue.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/metadata/values/DateMetaValue.java @@ -13,11 +13,14 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.time.Instant; -import java.time.ZoneId; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.stream.Collectors; import java.util.stream.LongStream; @@ -48,7 +51,7 @@ public DateMetaValue() { * * @param values The array of values. */ - public DateMetaValue(ZonedDateTime... values) { + public DateMetaValue(LocalDateTime... values) { m_value = Arrays.asList(values); } @@ -58,7 +61,7 @@ public DateMetaValue(ZonedDateTime... values) { * @param value The number of milliseconds since epoch. */ public DateMetaValue(long value) { - this(zonedDateTimeFromEpochMillis(value)); + this(localDateTimeFrom(value)); } /** @@ -96,30 +99,30 @@ public int compareTo( Object o ) { } /** - * Get the first native {@link ZonedDateTime} array value. + * Get the first native {@link LocalDateTime} array value. * * @return Returns said value. */ - public ZonedDateTime getDateValue() { + public LocalDateTime getDateValue() { return getDateValueAt(0); } /** - * Gets the {@link ZonedDateTime} value at the given index. + * Gets the {@link LocalDateTime} value at the given index. * * @param index The index of the value to get. * @return Returns said value. */ - public ZonedDateTime getDateValueAt( int index ) { + public LocalDateTime getDateValueAt( int index ) { return m_value.get(index); } /** - * Get the native {@link ZonedDateTime} array value. + * Get the native {@link LocalDateTime} array value. * * @return Returns said array. */ - public List getDateValues() { + public List getDateValues() { return m_value; } @@ -128,7 +131,7 @@ public List getDateValues() { */ @Override public long getLongValueAt(int index) { - return getDateValueAt(index).toInstant().toEpochMilli(); + return epocMilliFrom(getDateValueAt(index)); } /** @@ -164,12 +167,12 @@ public boolean isLegalValue( String value ) { } /** - * Sets the {@link ZonedDateTime} value at the given index. + * Sets the {@link LocalDateTime} value at the given index. * * @param newValue The new value. * @param index The index to set the value of. */ - public synchronized void setDateValueAt(ZonedDateTime newValue, int index) { + public synchronized void setDateValueAt(LocalDateTime newValue, int index) { checkIsEditable(); if (index >= m_value.size()) m_value.addAll(Collections.nCopies(index + 1 - m_value.size(), null)); @@ -182,7 +185,7 @@ public synchronized void setDateValueAt(ZonedDateTime newValue, int index) { */ @Override public void setLongValue( long newValue ) { - setDateValueAt(zonedDateTimeFromEpochMillis(newValue), 0); + setDateValueAt(localDateTimeFrom(newValue), 0); } /** @@ -227,7 +230,7 @@ public void readExternal( ObjectInput in ) throws IOException { throw new RuntimeException(e); } }) - .mapToObj(DateMetaValue::zonedDateTimeFromEpochMillis) + .mapToObj(DateMetaValue::localDateTimeFrom) .collect(Collectors.toList()); } @@ -239,8 +242,8 @@ public void readExternal( ObjectInput in ) throws IOException { @Override public void writeExternal( ObjectOutput out ) throws IOException { writeHeader( out ); - for ( ZonedDateTime value : m_value ) - out.writeLong( value.toInstant().toEpochMilli() ); + for ( var value : m_value ) + out.writeLong(epocMilliFrom(value)); } ////////// protected ////////////////////////////////////////////////////// @@ -254,7 +257,7 @@ public void writeExternal( ObjectOutput out ) throws IOException { */ @Override protected void appendValueImpl( String newValue ) { - final ZonedDateTime newDateTime = parseValue(newValue); + final LocalDateTime newDateTime = parseValue(newValue); m_value.add(newDateTime); } @@ -303,18 +306,18 @@ protected String toStringImpl() { * Parse a date from a {@link String}. * * @param value The {@link String} to parse. - * @return Returns a {link ZonedDateTime}. + * @return Returns a {link LocalDateTime}. * @throws IllegalArgumentException if the {@link String} does not contain * a parsable date. */ - private static @NotNull ZonedDateTime parseValue(String value) { + private static @NotNull LocalDateTime parseValue(String value) { // // Try parsing the value using all the expected date formats until one // parses successfully. // for (final var formatter : m_dateFormatters) { try { - return ZonedDateTime.parse(value, formatter); + return LocalDateTime.parse(value, formatter); } catch (DateTimeParseException e) { // ignore } @@ -329,9 +332,13 @@ protected String toStringImpl() { private static final DateTimeFormatter m_canonicalDateFormatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); - private static @NotNull ZonedDateTime zonedDateTimeFromEpochMillis(long epochMillis) { + private static @NotNull LocalDateTime localDateTimeFrom(long epochMillis) { final var instant = Instant.ofEpochMilli(epochMillis); - return ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); + return LocalDateTime.ofInstant(instant, ZoneOffset.UTC); + } + + private static long epocMilliFrom(@NotNull LocalDateTime value) { + return value.toInstant(ZoneOffset.UTC).toEpochMilli(); } /** @@ -350,6 +357,6 @@ protected String toStringImpl() { ); @NotNull - private List m_value = new ArrayList<>(); + private List m_value = new ArrayList<>(); } /* vim:set et sw=4 ts=4: */ diff --git a/lightcrafts/src/main/java/com/lightcrafts/image/types/RawImageCache.java b/lightcrafts/src/main/java/com/lightcrafts/image/types/RawImageCache.java index 6732f4bf..6b60e183 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/image/types/RawImageCache.java +++ b/lightcrafts/src/main/java/com/lightcrafts/image/types/RawImageCache.java @@ -21,6 +21,7 @@ import java.awt.image.RenderedImage; import java.io.File; import java.io.IOException; +import java.time.ZoneOffset; /** * TODO. @@ -73,7 +74,7 @@ static String getCacheKeyFor( ImageInfo imageInfo ) captureDate = dcRaw.getCaptureDateTime(); } if ( captureDate != null ) { - final long time = captureDate.toInstant().toEpochMilli(); + final long time = captureDate.toInstant(ZoneOffset.UTC).toEpochMilli(); return imageInfo.getFile().getName() + time + version; } return null; diff --git a/lightcrafts/src/main/java/com/lightcrafts/utils/TerseLoggingHandler.java b/lightcrafts/src/main/java/com/lightcrafts/utils/TerseLoggingHandler.java index fb75fd67..48a9980f 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/utils/TerseLoggingHandler.java +++ b/lightcrafts/src/main/java/com/lightcrafts/utils/TerseLoggingHandler.java @@ -5,7 +5,7 @@ import java.io.OutputStream; import java.time.ZoneId; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.logging.Formatter; import java.util.logging.LogRecord; @@ -29,7 +29,6 @@ public void close() { class TerseLoggingFormatter extends Formatter { - private final static String format = "{0,date} {0,time}"; private final static String format = "yyyy:MM:dd HH:mm:ss"; private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format); @@ -38,7 +37,7 @@ class TerseLoggingFormatter extends Formatter { @Override public synchronized String format(LogRecord record) { final StringBuilder sb = new StringBuilder(); - final var dateTime = ZonedDateTime.ofInstant(record.getInstant(), ZoneId.systemDefault()); + final var dateTime = LocalDateTime.ofInstant(record.getInstant(), ZoneId.systemDefault()); sb.append(dateTime.format(formatter)); sb.append(" "); String name = record.getSourceClassName(); diff --git a/lightcrafts/src/main/java/com/lightcrafts/utils/raw/DCRaw.java b/lightcrafts/src/main/java/com/lightcrafts/utils/raw/DCRaw.java index 39782ca1..c521713e 100644 --- a/lightcrafts/src/main/java/com/lightcrafts/utils/raw/DCRaw.java +++ b/lightcrafts/src/main/java/com/lightcrafts/utils/raw/DCRaw.java @@ -26,7 +26,8 @@ import java.nio.channels.FileChannel; import java.time.Instant; import java.time.ZoneId; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.time.format.DateTimeParseException; import java.util.*; @@ -115,11 +116,11 @@ public float[][] getCameraXYZ() { * {@inheritDoc} */ @Override - public ZonedDateTime getCaptureDateTime() { + public LocalDateTime getCaptureDateTime() { if (m_captureDateTime <= 0) return null; final var instant = Instant.ofEpochMilli(m_captureDateTime); - return ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); + return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); } public float[] getDaylightMultipliers() { @@ -250,8 +251,8 @@ private void parseDCRawInfo(String line, boolean secondary) { if (line.startsWith(search = TIMESTAMP)) { final var timestamp = line.substring(search.length()); try { - m_captureDateTime = ZonedDateTime.parse(timestamp, ISO_LOCAL_DATE_TIME) - .toInstant() + m_captureDateTime = LocalDateTime.parse(timestamp, ISO_LOCAL_DATE_TIME) + .toInstant(ZoneOffset.UTC) .toEpochMilli(); } catch (DateTimeParseException e) { m_captureDateTime = 0; diff --git a/lightcrafts/src/test/java/com/lightcrafts/image/metadata/values/DateMetaValueTest.java b/lightcrafts/src/test/java/com/lightcrafts/image/metadata/values/DateMetaValueTest.java index 1caadca9..edded7c9 100644 --- a/lightcrafts/src/test/java/com/lightcrafts/image/metadata/values/DateMetaValueTest.java +++ b/lightcrafts/src/test/java/com/lightcrafts/image/metadata/values/DateMetaValueTest.java @@ -2,7 +2,8 @@ import org.junit.jupiter.api.Test; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -10,11 +11,11 @@ class DateMetaValueTest { @Test - void shouldCreateWithZonedDateTimeArray() { - final ZonedDateTime[] dates = {ZonedDateTime.now(), ZonedDateTime.now().plusDays(1)}; + void shouldCreateWithLocalDateTimeArray() { + final LocalDateTime[] dates = {LocalDateTime.now(), LocalDateTime.now().plusDays(1)}; final var dateMetaValue = new DateMetaValue(dates); - final List result = dateMetaValue.getDateValues(); + final List result = dateMetaValue.getDateValues(); assertArrayEquals(dates, result.toArray()); } @@ -24,9 +25,9 @@ void shouldCreateWithLongValue() { final long epochMillis = System.currentTimeMillis(); final var dateMetaValue = new DateMetaValue(epochMillis); - final ZonedDateTime result = dateMetaValue.getDateValue(); + final LocalDateTime result = dateMetaValue.getDateValue(); - assertEquals(epochMillis, result.toInstant().toEpochMilli()); + assertEquals(epochMillis, result.toInstant(ZoneOffset.UTC).toEpochMilli()); } @Test @@ -34,10 +35,10 @@ void shouldCreateWithStringArray() { final String[] dates = {"2022-12-31T23:59:59", "2023-01-01T00:00:00"}; final var dateMetaValue = new DateMetaValue(dates); - final List result = dateMetaValue.getDateValues(); + final List result = dateMetaValue.getDateValues(); - assertEquals(ZonedDateTime.parse(dates[0]), result.get(0)); - assertEquals(ZonedDateTime.parse(dates[1]), result.get(1)); + assertEquals(LocalDateTime.parse(dates[0]), result.get(0)); + assertEquals(LocalDateTime.parse(dates[1]), result.get(1)); } @Test @@ -64,7 +65,7 @@ void shouldReturnFalseForIllegalValue() { @Test void shouldThrowExceptionWhenSettingValueForNonEditableInstance() { final var dateMetaValue = new DateMetaValue(); - final var date = ZonedDateTime.now(); + final var date = LocalDateTime.now(); assertThrows(IllegalStateException.class, () -> dateMetaValue.setDateValueAt(date, 2)); } @@ -73,7 +74,7 @@ void shouldThrowExceptionWhenSettingValueForNonEditableInstance() { void shouldSetValueAtSpecificIndex() { final var dateMetaValue = new DateMetaValue(); dateMetaValue.setIsChangeable(true); - final var date = ZonedDateTime.now(); + final var date = LocalDateTime.now(); dateMetaValue.setDateValueAt(date, 2); @@ -84,7 +85,7 @@ void shouldSetValueAtSpecificIndex() { void shouldThrowExceptionWhenSettingValueAtNegativeIndex() { final var dateMetaValue = new DateMetaValue(); dateMetaValue.setIsChangeable(true); - final var date = ZonedDateTime.now(); + final var date = LocalDateTime.now(); assertThrows(IndexOutOfBoundsException.class, () -> dateMetaValue.setDateValueAt(date, -1)); }