Skip to content

Commit

Permalink
Fixed illegal date parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanOltmann committed Feb 3, 2024
1 parent 67dfddd commit 49d82de
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Source/com/drew/metadata/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 49d82de

Please sign in to comment.