Changeset 9499 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ExifReader.java
r9383 r9499 42 42 Metadata metadata = JpegMetadataReader.readMetadata(filename); 43 43 String dateStr = null; 44 OUTER:44 String subSeconds = null; 45 45 for (Directory dirIt : metadata.getDirectories()) { 46 46 for (Tag tag : dirIt.getTags()) { … … 48 48 !tag.getDescription().matches("\\[[0-9]+ .+\\]")) { 49 49 dateStr = tag.getDescription(); 50 break OUTER; // prefer this tag if known51 50 } 52 51 if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */ || 53 52 tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) { 54 dateStr = tag.getDescription(); 53 if (dateStr != null) { 54 // prefer TAG_DATETIME_ORIGINAL 55 dateStr = tag.getDescription(); 56 } 57 } 58 if (tag.getTagType() == ExifIFD0Directory.TAG_SUBSECOND_TIME_ORIGINAL) { 59 subSeconds = tag.getDescription(); 55 60 } 56 61 } … … 58 63 if (dateStr != null) { 59 64 dateStr = dateStr.replace('/', ':'); // workaround for HTC Sensation bug, see #7228 60 return DateUtils.fromString(dateStr); 65 final Date date = DateUtils.fromString(dateStr); 66 if (subSeconds != null) { 67 try { 68 date.setTime(date.getTime() + Integer.parseInt(subSeconds)); 69 } catch (NumberFormatException e) { 70 Main.warn("Failed parsing sub seconds from [{0}]", subSeconds); 71 Main.warn(e); 72 } 73 } 74 return date; 61 75 } 62 76 } catch (Exception e) { -
trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java
r9394 r9499 8 8 import java.text.DecimalFormat; 9 9 import java.text.ParseException; 10 import java.text.SimpleDateFormat; 10 11 import java.util.Calendar; 11 12 import java.util.Date; … … 47 48 48 49 /** 50 * Tests reading sub-seconds from the EXIF header 51 * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file 52 */ 53 @Test 54 public void testReadTimeSubSecond1() throws ParseException { 55 Date date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg")); 56 String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date); 57 assertEquals("2015-07-11T19:34:19.100", dateStr); 58 } 59 60 /** 49 61 * Test orientation extraction 50 62 */
Note: See TracChangeset
for help on using the changeset viewer.