Skip to content

Commit

Permalink
fix: Replace ZonedDateTime with LocalDateTime
Browse files Browse the repository at this point in the history
* Use UTC to calculate milli seconds from epoch
  • Loading branch information
ktgw0316 committed Dec 12, 2023
1 parent ec312e2 commit 7b2d855
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 81 deletions.
4 changes: 4 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
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.*;
import static com.lightcrafts.image.metadata.ImageMetaType.*;
import static com.lightcrafts.image.metadata.ImageOrientation.ORIENTATION_LANDSCAPE;
import static com.lightcrafts.image.metadata.ImageOrientation.ORIENTATION_UNKNOWN;
import static com.lightcrafts.image.metadata.XMPConstants.*;
import static java.time.format.DateTimeFormatter.*;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME;

/**
* A <code>CoreDirectory</code> is-an {@link ImageMetadataDirectory} for
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -510,22 +510,17 @@ protected Collection<Element> toXMP( Document xmpDoc, String nsURI,

////////// MetadataDate & ModifyDate

final var now = ZonedDateTime.now();
// final String now = ZonedDateTime.now().format(ISO_OFFSET_DATE_TIME);
final String now = LocalDateTime.now().format(ISO_LOCAL_DATE_TIME);
final Element metadataDateElement = xmpDoc.createElementNS(
XMP_XAP_NS, XMP_XAP_PREFIX + ":MetadataDate"
);
XMLUtil.setTextContentOf(
metadataDateElement,
now.format(ISO_OFFSET_DATE_TIME)
);
XMLUtil.setTextContentOf(metadataDateElement, now);
xapRDFDescElement.appendChild( metadataDateElement );
final Element modifyDateElement = xmpDoc.createElementNS(
XMP_XAP_NS, XMP_XAP_PREFIX + ":ModifyDate"
);
XMLUtil.setTextContentOf(
modifyDateElement,
now.format(ISO_OFFSET_DATE_TIME)
);
XMLUtil.setTextContentOf(modifyDateElement, now);
xapRDFDescElement.appendChild( modifyDateElement );

////////// Rating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -258,7 +258,7 @@ public String getCaption() {
/**
* {@inheritDoc}
*/
public ZonedDateTime getCaptureDateTime() {
public LocalDateTime getCaptureDateTime() {
final Collection<ImageMetadataDirectory> dirs =
findProvidersOf( CaptureDateTimeProvider.class );
for ( ImageMetadataDirectory dir : dirs ) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import org.jetbrains.annotations.Nullable;

import java.time.ZonedDateTime;
import java.time.LocalDateTime;

/**
* A <code>CaptureDateTimeProvider</code> provides the capture date/time of an
Expand All @@ -22,7 +22,7 @@ public interface CaptureDateTimeProvider extends ImageMetadataProvider {
* available.
*/
@Nullable
ZonedDateTime getCaptureDateTime();
LocalDateTime getCaptureDateTime();

}
/* vim:set et sw=4 ts=4: */
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import org.jetbrains.annotations.Nullable;

import java.time.ZonedDateTime;
import java.time.LocalDateTime;

/**
* A <code>FileDateTimeProvider</code> provides the last modified date/time of
Expand All @@ -22,7 +22,7 @@ public interface FileDateTimeProvider extends ImageMetadataProvider {
* available.
*/
@Nullable
ZonedDateTime getFileDateTime();
LocalDateTime getFileDateTime();

}
/* vim:set et sw=4 ts=4: */
Loading

0 comments on commit 7b2d855

Please sign in to comment.