I am using version 2.6.4 of the metadata-extractor library. The following test
case when run with the attached file as an argument demonstrates a problem with
reporting the creation date. On the particular camera I used for the image (a
Nikon E5700v1.0), if the date has not been set, the metadata records the date
as "0000:00:00 00:00:00" rather than the expected " : : : : ". The
test program therefore prints out:
Creation date is: Sun Nov 30 00:00:00 MST 2
rather than the expected output of:
No creation date recorded.
Here is the test program:
import java.text.*;
import java.util.Date;
import java.io.File;
import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifSubIFDDirectory;
public class testDate
{
public static void main(String args[]) throws Exception
{
File f = new File(args[0]);
Metadata metadata = ImageMetadataReader.readMetadata(f);
// obtain the Exif directory
ExifSubIFDDirectory directory =
metadata.getDirectory(ExifSubIFDDirectory.class);
try
{
// query the tag's value
Date file_date =
directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
System.out.println("Creation date is: " + file_date);
}
catch (NullPointerException npe)
{
System.out.println("No creation date recorded.");
}
}
}
I suggest this fix to the library:
diff --git a/Source/com/drew/metadata/Directory.java
b/Source/com/drew/metadata/Directory.java
index 282bc32..145e930 100644
--- a/Source/com/drew/metadata/Directory.java
+++ b/Source/com/drew/metadata/Directory.java
@@ -743,6 +743,10 @@ public abstract class Directory
return (java.util.Date)o;
if (o instanceof String) {
+ String dateString = (String)o;
+ if ("0000:00:00 00:00:00".equals(o))
+ return null;
+
// This seems to cover all known Exif date strings
// Note that " : : : : " is a valid date string according to the Exif spec (which means 'unknown date'): http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/datetimeoriginal.html
String datePatterns[] = {
@@ -752,7 +756,6 @@ public abstract class Directory
"yyyy-MM-dd HH:mm",
"yyyy.MM.dd HH:mm:ss",
"yyyy.MM.dd HH:mm" };
- String dateString = (String)o;
for (String datePattern : datePatterns) {
try {
DateFormat parser = new SimpleDateFormat(datePattern);
You may use the attached file for regression testing purposes.
Original issue reported on code.google.com by gdbent...@gmail.com on 9 Jul 2013 at 4:20
Original issue reported on code.google.com by
gdbent...@gmail.com
on 9 Jul 2013 at 4:20Attachments: