Changeset 11514 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ExifReader.java
r11484 r11514 44 44 Metadata metadata = JpegMetadataReader.readMetadata(filename); 45 45 String dateStr = null; 46 String dateTime = null; 46 47 String subSeconds = null; 47 48 for (Directory dirIt : metadata.getDirectories()) { … … 52 53 if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL /* 0x9003 */ && 53 54 !tag.getDescription().matches("\\[[0-9]+ .+\\]")) { 55 // prefer DATETIME_ORIGINAL 54 56 dateStr = tag.getDescription(); 55 57 } 56 if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */ ||57 tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) {58 if (dateStr == null) {59 // prefer TAG_DATETIME_ORIGINAL60 dateStr = tag.getDescription();61 }58 if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */) { 59 // prefer DATETIME over DATETIME_DIGITIZED 60 dateTime = tag.getDescription(); 61 } 62 if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */ && dateTime == null) { 63 dateTime = tag.getDescription(); 62 64 } 63 65 if (tag.getTagType() == ExifIFD0Directory.TAG_SUBSECOND_TIME_ORIGINAL) { … … 65 67 } 66 68 } 69 } 70 if (dateStr == null) { 71 dateStr = dateTime; 67 72 } 68 73 if (dateStr != null) { -
trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java
r11484 r11514 24 24 25 25 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 26 26 27 /** 27 28 * EXIF metadata extraction test … … 70 71 public void testReadTimeSubSecond1() throws ParseException { 71 72 Date date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg")); 72 String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date); 73 assertEquals("2015-07-11T19:34:19.100", dateStr); 73 doTest("2015-07-11T19:34:19.100", date); 74 74 75 75 TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin")); 76 76 date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg")); 77 77 TimeZone.setDefault(DateUtils.UTC); 78 dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date); 79 assertEquals("2015-07-11T17:34:19.100", dateStr); 78 doTest("2015-07-11T17:34:19.100", date); 79 } 80 81 private static void doTest(String expectedDate, Date parsedDate) { 82 assertEquals(expectedDate, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(parsedDate)); 83 } 84 85 private static void doTestFile(String expectedDate, int ticket, String filename) { 86 doTest(expectedDate, ExifReader.readTime(new File(TestUtils.getRegressionDataFile(ticket, filename)))); 80 87 } 81 88 … … 115 122 @Test 116 123 public void testTicket11685() throws IOException { 117 File file = new File(TestUtils.getRegressionDataFile(11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg")); 118 String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(ExifReader.readTime(file)); 119 assertEquals("2015-11-08T15:33:27.500", dateStr); 124 doTestFile("2015-11-08T15:33:27.500", 11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg"); 120 125 } 121 126 … … 126 131 @Test 127 132 public void testTicket14209() throws IOException { 128 File file = new File(TestUtils.getRegressionDataFile(14209, "0MbEfj1S--.1.jpg")); 129 String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(ExifReader.readTime(file)); 130 assertEquals("2017-01-16T18:27:00.000", dateStr); 133 doTestFile("2017-01-16T18:27:00.000", 14209, "0MbEfj1S--.1.jpg"); 134 doTestFile("2016-08-13T19:51:13.000", 14209, "7VWFOryj--.1.jpg"); 131 135 } 132 136 }
Note:
See TracChangeset
for help on using the changeset viewer.