Ignore:
Timestamp:
2021-04-08T22:56:06+02:00 (4 years ago)
Author:
simon04
Message:

see #14176 - Migrate GPX to Instant

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

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

    r17548 r17715  
    66import java.io.IOException;
    77import java.time.DateTimeException;
     8import java.time.Instant;
    89import java.util.Date;
    910import java.util.List;
     
    4243     * @param filename The JPEG file to read
    4344     * @return The date/time read in the EXIF section, or {@code null} if not found
    44      */
     45     * @deprecated Use {@link #readInstant(File)}
     46     */
     47    @Deprecated
    4548    public static Date readTime(File filename) {
    46         try {
    47             final Metadata metadata = JpegMetadataReader.readMetadata(filename);
    48             return readTime(metadata);
     49        Instant instant = readInstant(filename);
     50        return instant == null ? null : Date.from(instant);
     51    }
     52
     53    /**
     54     * Returns the date/time from the given JPEG file.
     55     * @param filename The JPEG file to read
     56     * @return The date/time read in the EXIF section, or {@code null} if not found
     57     */
     58    public static Instant readInstant(File filename) {
     59        try {
     60            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     61            return readInstant(metadata);
    4962        } catch (JpegProcessingException | IOException e) {
    5063            Logging.error(e);
     
    5871     * @return The date/time read in the EXIF section, or {@code null} if not found
    5972     * @since 11745
    60      */
     73     * @deprecated Use {@link #readInstant(Metadata)}
     74     */
     75    @Deprecated
    6176    public static Date readTime(Metadata metadata) {
     77        Instant instant = readInstant(metadata);
     78        return instant == null ? null : Date.from(instant);
     79    }
     80
     81    /**
     82     * Returns the date/time from the given JPEG file.
     83     * @param metadata The EXIF metadata
     84     * @return The date/time read in the EXIF section, or {@code null} if not found
     85     */
     86    public static Instant readInstant(Metadata metadata) {
    6287        try {
    6388            String dateTimeOrig = null;
     
    109134            if (dateStr != null) {
    110135                dateStr = dateStr.replace('/', ':'); // workaround for HTC Sensation bug, see #7228
    111                 final Date date = DateUtils.fromString(dateStr);
     136                Instant date = DateUtils.parseInstant(dateStr);
    112137                if (subSeconds != null) {
    113138                    try {
    114                         date.setTime(date.getTime() + (long) (TimeUnit.SECONDS.toMillis(1) * Double.parseDouble("0." + subSeconds)));
     139                        date = date.plusMillis((long) (TimeUnit.SECONDS.toMillis(1) * Double.parseDouble("0." + subSeconds)));
    115140                    } catch (NumberFormatException e) {
    116141                        Logging.warn("Failed parsing sub seconds from [{0}]", subSeconds);
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r17712 r17715  
    287287     * @return the date format used for GPX waypoints
    288288     * @since 14055
    289      */
     289     * @deprecated Use {@link Instant#toString()}
     290     */
     291    @Deprecated
    290292    public static DateFormat getGpxFormat() {
    291293        SimpleDateFormat result = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Note: See TracChangeset for help on using the changeset viewer.