Changeset 9672 in josm


Ignore:
Timestamp:
2016-01-29T19:53:36+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #11685 - parse subsecond exif information correctly

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r9648 r9672  
    77import java.util.Date;
    88
    9 import com.drew.metadata.exif.ExifDirectoryBase;
    109import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.data.coor.LatLon;
     
    1918import com.drew.metadata.MetadataException;
    2019import com.drew.metadata.Tag;
     20import com.drew.metadata.exif.ExifDirectoryBase;
    2121import com.drew.metadata.exif.ExifIFD0Directory;
    2222import com.drew.metadata.exif.ExifSubIFDDirectory;
     
    7070                if (subSeconds != null) {
    7171                    try {
    72                         date.setTime(date.getTime() + Integer.parseInt(subSeconds));
     72                        date.setTime(date.getTime() + (long) (1000L * Double.parseDouble("0." + subSeconds)));
    7373                    } catch (NumberFormatException e) {
    7474                        Main.warn("Failed parsing sub seconds from [{0}]", subSeconds);
  • trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java

    r9499 r9672  
    66
    77import java.io.File;
     8import java.io.IOException;
    89import java.text.DecimalFormat;
    910import java.text.ParseException;
     
    1617import org.junit.Before;
    1718import org.junit.Test;
     19import org.openstreetmap.josm.TestUtils;
    1820import org.openstreetmap.josm.data.coor.LatLon;
    1921import org.openstreetmap.josm.tools.date.DateUtilsTest;
     
    4951    /**
    5052     * Tests reading sub-seconds from the EXIF header
    51      * @throws ParseException  if {@link ExifReader#readTime} fails to parse date/time of sample file
     53     * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
    5254     */
    5355    @Test
     
    8082
    8183    /**
    82      * Test coordinates extraction
     84     * Test direction extraction
    8385     */
    8486    @Test
     
    8789        assertEquals(new Double(46.5), direction);
    8890    }
     91
     92    /**
     93     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/11685">#11685</a>
     94     * @throws IOException if an error occurs during reading
     95     */
     96    @Test
     97    public void testTicket11685() throws IOException {
     98        File file = new File(TestUtils.getRegressionDataFile(11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg"));
     99        String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(ExifReader.readTime(file));
     100        assertEquals("2015-11-08T15:33:27.500", dateStr);
     101    }
    89102}
Note: See TracChangeset for help on using the changeset viewer.