From 49d82ded4043ba64d4dedfc8fe3a7ba747615842 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Sat, 3 Feb 2024 16:54:56 +0100 Subject: [PATCH] Fixed illegal date parsing. --- Source/com/drew/metadata/Directory.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/com/drew/metadata/Directory.java b/Source/com/drew/metadata/Directory.java index db5234a61..c63f26ede 100644 --- a/Source/com/drew/metadata/Directory.java +++ b/Source/com/drew/metadata/Directory.java @@ -895,6 +895,12 @@ public java.util.Date getDate(int tagType, @Nullable String subsecond, @Nullable String dateString = o.toString(); + /* + * This is a common NULL value known for cameras like Olympus C750UZ. + */ + if (dateString.equals("0000:00:00 00:00:00")) + return null; + // if the date string has subsecond information, it supersedes the subsecond parameter Pattern subsecondPattern = Pattern.compile("(\\d\\d:\\d\\d:\\d\\d)(\\.\\d+)"); Matcher subsecondMatcher = subsecondPattern.matcher(dateString); @@ -913,7 +919,23 @@ public java.util.Date getDate(int tagType, @Nullable String subsecond, @Nullable for (String datePattern : datePatterns) { try { + DateFormat parser = new SimpleDateFormat(datePattern); + + /* + * Some older digital cameras, such as the Olympus C750UZ, may not have recorded a proper + * exif:DateTimeOriginal value. Instead of leaving this field empty, they used + * 0000:00:00 00:00:00 as a placeholder. + * + * "0000:00:00 00:00:00" will result in "Sun Nov 30 00:00:00 GMT 2", + * which is not what a user would expect. + * + * Any illegal formats should result in an exception and not be parsed. + * + * It's best to turn lenient mode off. + */ + parser.setLenient(false); + if (timeZone != null) parser.setTimeZone(timeZone); else