Changeset 17715 in josm


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

see #14176 - Migrate GPX to Instant

Location:
trunk
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r17439 r17715  
    44import java.io.File;
    55import java.text.MessageFormat;
     6import java.time.Instant;
    67import java.util.ArrayList;
    78import java.util.Arrays;
     
    910import java.util.Collections;
    1011import java.util.Comparator;
    11 import java.util.Date;
    1212import java.util.HashMap;
    1313import java.util.HashSet;
     
    200200                boolean split = false;
    201201                WayPoint prevLastOwnWp = null;
    202                 Date prevWpTime = null;
     202                Instant prevWpTime = null;
    203203                for (WayPoint wp : wpsOld) {
    204                     Date wpTime = wp.getDate();
     204                    Instant wpTime = wp.getInstant();
    205205                    boolean overlap = false;
    206206                    if (wpTime != null) {
    207207                        for (GpxTrackSegmentSpan ownspan : getSegmentSpans()) {
    208                             if (wpTime.after(ownspan.firstTime) && wpTime.before(ownspan.lastTime)) {
     208                            if (wpTime.isAfter(ownspan.firstTime) && wpTime.isBefore(ownspan.lastTime)) {
    209209                                overlap = true;
    210210                                if (connect) {
     
    219219                                break;
    220220                            } else if (connect && prevWpTime != null
    221                                     && prevWpTime.before(ownspan.firstTime)
    222                                     && wpTime.after(ownspan.lastTime)) {
     221                                    && prevWpTime.isBefore(ownspan.firstTime)
     222                                    && wpTime.isAfter(ownspan.lastTime)) {
    223223                                // the overlapping high priority track is shorter than the distance
    224224                                // between two waypoints of the low priority track
     
    287287    static class GpxTrackSegmentSpan {
    288288
    289         final Date firstTime;
    290         final Date lastTime;
     289        final Instant firstTime;
     290        final Instant lastTime;
    291291        private final boolean inv;
    292292        private final WayPoint firstWp;
     
    294294
    295295        GpxTrackSegmentSpan(WayPoint a, WayPoint b) {
    296             Date at = a.getDate();
    297             Date bt = b.getDate();
    298             inv = bt.before(at);
     296            Instant at = a.getInstant();
     297            Instant bt = b.getInstant();
     298            inv = bt.isBefore(at);
    299299            if (inv) {
    300300                firstWp = b;
     
    333333
    334334        boolean overlapsWith(GpxTrackSegmentSpan other) {
    335             return (firstTime.before(other.lastTime) && other.firstTime.before(lastTime))
    336                 || (other.firstTime.before(lastTime) && firstTime.before(other.lastTime));
     335            return (firstTime.isBefore(other.lastTime) && other.firstTime.isBefore(lastTime))
     336                || (other.firstTime.isBefore(lastTime) && firstTime.isBefore(other.lastTime));
    337337        }
    338338
     
    720720     * @return  minimum and maximum dates in array of 2 elements
    721721     */
    722     public static Date[] getMinMaxTimeForTrack(IGpxTrack trk) {
     722    public static Instant[] getMinMaxTimeForTrack(IGpxTrack trk) {
    723723        final LongSummaryStatistics statistics = trk.getSegments().stream()
    724724                .flatMap(seg -> seg.getWayPoints().stream())
     
    727727        return statistics.getCount() == 0 || (statistics.getMin() == 0 && statistics.getMax() == 0)
    728728                ? null
    729                 : new Date[]{new Date(statistics.getMin()), new Date(statistics.getMax())};
     729                : new Instant[]{Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax())};
    730730    }
    731731
     
    737737    * @since 7319
    738738    */
    739     public synchronized Date[] getMinMaxTimeForAllTracks() {
     739    public synchronized Instant[] getMinMaxTimeForAllTracks() {
    740740        long now = System.currentTimeMillis();
    741741        final LongSummaryStatistics statistics = tracks.stream()
     
    746746                .summaryStatistics();
    747747        return statistics.getCount() == 0
    748                 ? new Date[0]
    749                 : new Date[]{new Date(statistics.getMin()), new Date(statistics.getMax())};
     748                ? new Instant[0]
     749                : new Instant[]{Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax())};
    750750    }
    751751
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java

    r17579 r17715  
    33
    44import java.util.ArrayList;
    5 import java.util.Date;
    65import java.util.List;
    76import java.util.concurrent.TimeUnit;
     
    226225                final GpxImageEntry curImg = images.get(i);
    227226                final GpxImageEntry curTmp = curImg.getTmp();
    228                 final long time = curImg.getExifTime().getTime();
     227                final long time = curImg.getExifInstant().toEpochMilli();
    229228                if ((!isLast && time > curWpTime) || time < prevWpTime) {
    230229                    break;
     
    239238                        curTmp.setPos(curWp.getCoor());
    240239                    }
    241                     curTmp.setGpsTime(new Date(curImg.getExifTime().getTime() - offset));
     240                    curTmp.setGpsTime(curImg.getExifInstant().minusMillis(offset));
    242241                    curTmp.flagNewGpsData();
    243242                    curImg.tmpUpdated();
     
    253252                GpxImageEntry curImg = images.get(i);
    254253                GpxImageEntry curTmp = curImg.getTmp();
    255                 final long imgTime = curImg.getExifTime().getTime();
     254                final long imgTime = curImg.getExifInstant().toEpochMilli();
    256255                if (imgTime < prevWpTime) {
    257256                    break;
     
    265264                        curTmp.setElevation(prevElevation + (curElevation - prevElevation) * timeDiff);
    266265                    }
    267                     curTmp.setGpsTime(new Date(curImg.getExifTime().getTime() - offset));
     266                    curTmp.setGpsTime(curImg.getExifInstant().minusMillis(offset));
    268267                    curTmp.flagNewGpsData();
    269268                    curImg.tmpUpdated();
     
    281280
    282281        // No photos or the first photo taken is later than the search period
    283         if (lstSize == 0 || searchedTime < images.get(0).getExifTime().getTime())
     282        if (lstSize == 0 || searchedTime < images.get(0).getExifInstant().toEpochMilli())
    284283            return -1;
    285284
    286285        // The search period is later than the last photo
    287         if (searchedTime > images.get(lstSize - 1).getExifTime().getTime())
     286        if (searchedTime > images.get(lstSize - 1).getExifInstant().toEpochMilli())
    288287            return lstSize-1;
    289288
     
    294293        while (endIndex - startIndex > 1) {
    295294            curIndex = (endIndex + startIndex) / 2;
    296             if (searchedTime > images.get(curIndex).getExifTime().getTime()) {
     295            if (searchedTime > images.get(curIndex).getExifInstant().toEpochMilli()) {
    297296                startIndex = curIndex;
    298297            } else {
     
    300299            }
    301300        }
    302         if (searchedTime < images.get(endIndex).getExifTime().getTime())
     301        if (searchedTime < images.get(endIndex).getExifInstant().toEpochMilli())
    303302            return startIndex;
    304303
    305304        // This final loop is to check if photos with the exact same EXIF time follows
    306         while ((endIndex < (lstSize - 1)) && (images.get(endIndex).getExifTime().getTime()
    307                 == images.get(endIndex + 1).getExifTime().getTime())) {
     305        while ((endIndex < (lstSize - 1)) && (images.get(endIndex).getExifInstant().toEpochMilli()
     306                == images.get(endIndex + 1).getExifInstant().toEpochMilli())) {
    308307            endIndex++;
    309308        }
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageEntry.java

    r17579 r17715  
    66import java.io.File;
    77import java.io.IOException;
     8import java.time.Instant;
    89import java.util.Date;
    910import java.util.List;
     
    4344    private LatLon exifCoor;
    4445    private Double exifImgDir;
    45     private Date exifTime;
     46    private Instant exifTime;
    4647    /**
    4748     * Flag isNewGpsData indicates that the GPS data of the image is new or has changed.
     
    5152    private boolean isNewGpsData;
    5253    /** Temporary source of GPS time if not correlated with GPX track. */
    53     private Date exifGpsTime;
     54    private Instant exifGpsTime;
    5455
    5556    private String iptcCaption;
     
    6869    private Double elevation;
    6970    /** The time after correlation with a gpx track */
    70     private Date gpsTime;
     71    private Instant gpsTime;
    7172
    7273    private int width;
     
    173174     * is returned if that copy exists.
    174175     * @return the GPS time value
    175      */
     176     * @deprecated Use {@link #getGpsInstant}
     177     */
     178    @Deprecated
    176179    public Date getGpsTime() {
    177180        if (tmp != null)
     
    181184
    182185    /**
     186     * Returns the GPS time value. The GPS time value from the temporary copy
     187     * is returned if that copy exists.
     188     * @return the GPS time value
     189     */
     190    public Instant getGpsInstant() {
     191        return tmp != null ? tmp.gpsTime : gpsTime;
     192    }
     193
     194    /**
    183195     * Convenient way to determine if this entry has a GPS time, without the cost of building a defensive copy.
    184196     * @return {@code true} if this entry has a GPS time
     
    208220     * Returns EXIF time
    209221     * @return EXIF time
    210      */
     222     * @deprecated Use {@link #getExifInstant}
     223     */
     224    @Deprecated
    211225    public Date getExifTime() {
    212226        return getDefensiveDate(exifTime);
     227    }
     228
     229    /**
     230     * Returns EXIF time
     231     * @return EXIF time
     232     */
     233    public Instant getExifInstant() {
     234        return exifTime;
    213235    }
    214236
     
    226248     * @return the EXIF GPS time
    227249     * @since 6392
    228      */
     250     * @deprecated Use {@link #getExifGpsInstant}
     251     */
     252    @Deprecated
    229253    public Date getExifGpsTime() {
    230254        return getDefensiveDate(exifGpsTime);
     255    }
     256
     257    /**
     258     * Returns the EXIF GPS time.
     259     * @return the EXIF GPS time
     260     */
     261    public Instant getExifGpsInstant() {
     262        return exifGpsTime;
    231263    }
    232264
     
    240272    }
    241273
    242     private static Date getDefensiveDate(Date date) {
     274    private static Date getDefensiveDate(Instant date) {
    243275        if (date == null)
    244276            return null;
    245         return new Date(date.getTime());
     277        return Date.from(date);
    246278    }
    247279
     
    325357     * Sets EXIF time.
    326358     * @param exifTime EXIF time
    327      */
     359     * @deprecated Use {@link #setExifTime(Instant)}
     360     */
     361    @Deprecated
    328362    public void setExifTime(Date exifTime) {
    329         this.exifTime = getDefensiveDate(exifTime);
     363        this.exifTime = exifTime == null ? null : exifTime.toInstant();
    330364    }
    331365
     
    334368     * @param exifGpsTime the EXIF GPS time
    335369     * @since 6392
    336      */
     370     * @deprecated Use {@link #setExifGpsTime(Instant)}
     371     */
     372    @Deprecated
    337373    public void setExifGpsTime(Date exifGpsTime) {
    338         this.exifGpsTime = getDefensiveDate(exifGpsTime);
    339     }
    340 
     374        this.exifGpsTime = exifGpsTime == null ? null : exifGpsTime.toInstant();
     375    }
     376
     377    /**
     378     * Sets the GPS time.
     379     * @param gpsTime the GPS time
     380     * @deprecated Use {@link #setGpsTime(Instant)}
     381     */
     382    @Deprecated
    341383    public void setGpsTime(Date gpsTime) {
    342         this.gpsTime = getDefensiveDate(gpsTime);
     384        this.gpsTime = gpsTime == null ? null : gpsTime.toInstant();
     385    }
     386
     387    /**
     388     * Sets EXIF time.
     389     * @param exifTime EXIF time
     390     */
     391    public void setExifTime(Instant exifTime) {
     392        this.exifTime = exifTime;
     393    }
     394
     395    /**
     396     * Sets the EXIF GPS time.
     397     * @param exifGpsTime the EXIF GPS time
     398     */
     399    public void setExifGpsTime(Instant exifGpsTime) {
     400        this.exifGpsTime = exifGpsTime;
     401    }
     402
     403    /**
     404     * Sets the GPS time.
     405     * @param gpsTime the GPS time
     406     */
     407    public void setGpsTime(Instant gpsTime) {
     408        this.gpsTime = gpsTime;
    343409    }
    344410
     
    635701                        Logging.warn(topException);
    636702                        Logging.info(tr("Can''t parse metadata for file \"{0}\". Using last modified date as timestamp.", fn));
    637                         setExifTime(new Date(file.lastModified()));
     703                        setExifTime(Instant.ofEpochMilli(file.lastModified()));
    638704                        setExifCoor(null);
    639705                        setPos(null);
     
    646712        // Changed to silently cope with no time info in exif. One case
    647713        // of person having time that couldn't be parsed, but valid GPS info
    648         Date time = null;
     714        Instant time = null;
    649715        try {
    650             time = ExifReader.readTime(metadata);
     716            time = ExifReader.readInstant(metadata);
    651717        } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException ex) {
    652718            Logging.warn(ex);
     
    655721        if (time == null) {
    656722            Logging.info(tr("No EXIF time in file \"{0}\". Using last modified date as timestamp.", fn));
    657             time = new Date(file.lastModified()); //use lastModified time if no EXIF time present
     723            time = Instant.ofEpochMilli(file.lastModified()); //use lastModified time if no EXIF time present
    658724        }
    659725        setExifTime(time);
     
    705771        }
    706772
    707         ifNotNull(dirGps.getGpsDate(), this::setExifGpsTime);
     773        ifNotNull(dirGps.getGpsDate(), d -> setExifGpsTime(d.toInstant()));
    708774
    709775        IptcDirectory dirIptc = metadata.getFirstDirectoryOfType(IptcDirectory.class);
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r17132 r17715  
    33
    44import java.awt.Color;
     5import java.time.Instant;
    56import java.util.ArrayList;
    67import java.util.Date;
     
    1617import org.openstreetmap.josm.tools.Logging;
    1718import org.openstreetmap.josm.tools.Utils;
    18 import org.openstreetmap.josm.tools.date.DateUtils;
    1919import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    2020
     
    6666        attr = new HashMap<>(0);
    6767        attr.putAll(p.attr);
    68         if (p.getDate() != null) {
    69             attr.put(PT_TIME, p.getDate());
    70         }
    7168        lat = p.lat;
    7269        lon = p.lon;
     
    139136     * @param time the time to set
    140137     * @since 9383
    141      */
     138     * @deprecated Use {@link #setInstant(Instant)}
     139     */
     140    @Deprecated
    142141    public void setTime(Date time) {
    143         setTimeInMillis(time.getTime());
     142        setInstant(time.toInstant());
    144143    }
    145144
     
    149148     * @param ts seconds from the epoch
    150149     * @since 13210
    151      */
     150     * @deprecated Use {@link #setInstant(Instant)}
     151     */
     152    @Deprecated
    152153    public void setTime(long ts) {
    153         setTimeInMillis(ts * 1000);
     154        setInstant(Instant.ofEpochSecond(ts));
    154155    }
    155156
     
    161162     */
    162163    public void setTimeInMillis(long ts) {
    163         attr.put(PT_TIME, new Date(ts));
     164        setInstant(Instant.ofEpochMilli(ts));
     165    }
     166
     167    /**
     168     * Sets the {@link #PT_TIME} attribute to the specified time.
     169     *
     170     * @param instant the time to set
     171     */
     172    public void setInstant(Instant instant) {
     173        attr.put(PT_TIME, instant);
    164174    }
    165175
     
    185195     */
    186196    public long getTimeInMillis() {
    187         Date d = getDateImpl();
    188         return d == null ? 0 : d.getTime();
     197        Instant d = getInstant();
     198        return d == null ? 0 : d.toEpochMilli();
    189199    }
    190200
     
    196206     */
    197207    public boolean hasDate() {
    198         return attr.get(PT_TIME) instanceof Date;
     208        return attr.get(PT_TIME) instanceof Instant;
    199209    }
    200210
     
    204214     * @return a copy of the Date object associated with this waypoint
    205215     * @since 14456
    206      */
     216     * @deprecated Use {@link #getInstant()}
     217     */
     218    @Deprecated
    207219    public Date getDate() {
    208         return DateUtils.cloneDate(getDateImpl());
    209     }
    210 
    211     /**
    212      * Returns the waypoint time Date object.
    213      *
    214      * @return the Date object associated with this waypoint
    215      */
    216     private Date getDateImpl() {
     220        Instant instant = getInstant();
     221        return instant == null ? null : Date.from(instant);
     222    }
     223
     224    /**
     225     * Returns the waypoint instant.
     226     *
     227     * @return the instant associated with this waypoint
     228     * @since 14456
     229     */
     230    public Instant getInstant() {
    217231        if (attr != null) {
    218232            final Object obj = attr.get(PT_TIME);
    219233
    220             if (obj instanceof Date) {
    221                 return (Date) obj;
     234            if (obj instanceof Instant) {
     235                return (Instant) obj;
    222236            } else if (obj == null) {
    223237                Logging.trace("Waypoint {0} value unset", PT_TIME);
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r17439 r17715  
    1010import java.awt.event.ActionEvent;
    1111import java.io.File;
    12 import java.text.DateFormat;
     12import java.time.Instant;
     13import java.time.format.DateTimeFormatter;
     14import java.time.format.FormatStyle;
     15import java.time.temporal.ChronoUnit;
    1316import java.util.ArrayList;
    1417import java.util.Arrays;
     
    157160     */
    158161    public static String getTimespanForTrack(IGpxTrack trk) {
    159         Date[] bounds = GpxData.getMinMaxTimeForTrack(trk);
     162        Instant[] bounds = GpxData.getMinMaxTimeForTrack(trk);
    160163        return bounds != null ? formatTimespan(bounds) : "";
    161164    }
     
    166169     * @return The timespan as a string
    167170     */
    168     public static String formatTimespan(Date[] bounds) {
     171    public static String formatTimespan(Instant[] bounds) {
    169172        String ts = "";
    170         DateFormat df = DateUtils.getDateFormat(DateFormat.SHORT);
     173        DateTimeFormatter df = DateUtils.getDateFormatter(FormatStyle.SHORT);
    171174        String earliestDate = df.format(bounds[0]);
    172175        String latestDate = df.format(bounds[1]);
    173176
    174177        if (earliestDate.equals(latestDate)) {
    175             DateFormat tf = DateUtils.getTimeFormat(DateFormat.SHORT);
     178            DateTimeFormatter tf = DateUtils.getTimeFormatter(FormatStyle.SHORT);
    176179            ts += earliestDate + ' ';
    177180            ts += tf.format(bounds[0]) + " - " + tf.format(bounds[1]);
    178181        } else {
    179             DateFormat dtf = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);
     182            DateTimeFormatter dtf = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.MEDIUM);
    180183            ts += dtf.format(bounds[0]) + " - " + dtf.format(bounds[1]);
    181184        }
    182185
    183         int diff = (int) (bounds[1].getTime() - bounds[0].getTime()) / 1000;
     186        long diff = ChronoUnit.SECONDS.between(bounds[1], bounds[0]);
    184187        ts += String.format(" (%d:%02d)", diff / 3600, (diff % 3600) / 60);
    185188        return ts;
     
    355358        long to = toDate.getTime();
    356359        for (IGpxTrack trk : data.getTracks()) {
    357             Date[] t = GpxData.getMinMaxTimeForTrack(trk);
     360            Instant[] t = GpxData.getMinMaxTimeForTrack(trk);
    358361
    359362            if (t == null) continue;
    360             long tm = t[1].getTime();
     363            long tm = t[1].toEpochMilli();
    361364            trackVisibility[i] = (tm == 0 && showWithoutDate) || (from <= tm && tm <= to);
    362365            i++;
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r17626 r17715  
    2424import java.io.IOException;
    2525import java.time.DateTimeException;
     26import java.time.Instant;
    2627import java.util.ArrayList;
    2728import java.util.Arrays;
     
    878879                wpt.setTimeInMillis(DateUtils.tsFromString(v));
    879880            } else if (!n.isTimestampEmpty()) {
    880                 wpt.setTime(Integer.toUnsignedLong(n.getRawTimestamp()));
     881                wpt.setInstant(Instant.ofEpochSecond(Integer.toUnsignedLong(n.getRawTimestamp())));
    881882            }
    882883        } catch (UncheckedParseException | DateTimeException e) {
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r17548 r17715  
    2828import java.text.ParseException;
    2929import java.text.SimpleDateFormat;
     30import java.time.Instant;
     31import java.time.ZoneOffset;
     32import java.time.format.DateTimeFormatter;
     33import java.time.format.FormatStyle;
    3034import java.util.ArrayList;
    3135import java.util.Arrays;
    3236import java.util.Collections;
    3337import java.util.Comparator;
    34 import java.util.Date;
    3538import java.util.Dictionary;
    3639import java.util.Hashtable;
     
    768771        void updateExifComponents(ImageEntry img) {
    769772            imgDisp.setImage(img);
    770             Date date = img.getExifTime();
     773            Instant date = img.getExifInstant();
    771774            if (date != null) {
    772                 DateFormat df = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);
    773                 df.setTimeZone(DateUtils.UTC); // EXIF data does not contain timezone information and is read as UTC
     775                DateTimeFormatter df = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.MEDIUM)
     776                        .withZone(ZoneOffset.UTC); // EXIF data does not contain timezone information and is read as UTC
    774777                lbExifTime.setText(df.format(date));
    775778                tfGpsTime.setText(df.format(date));
     
    12601263
    12611264        // Init variables
    1262         long firstExifDate = imgs.get(0).getExifTime().getTime();
     1265        long firstExifDate = imgs.get(0).getExifInstant().toEpochMilli();
    12631266
    12641267        // Finds first GPX point
     
    13341337                .filter(e -> e.getExifCoor() == null || exif)
    13351338                .filter(e -> tagged || !e.isTagged() || e.getExifCoor() != null)
    1336                 .sorted(Comparator.comparing(ImageEntry::getExifTime))
     1339                .sorted(Comparator.comparing(ImageEntry::getExifInstant))
    13371340                .collect(Collectors.toList());
    13381341    }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r17188 r17715  
    1313import java.awt.event.KeyEvent;
    1414import java.awt.event.WindowEvent;
    15 import java.text.DateFormat;
    16 import java.text.SimpleDateFormat;
     15import java.time.ZoneOffset;
     16import java.time.format.DateTimeFormatter;
     17import java.time.format.FormatStyle;
    1718import java.util.Collections;
    1819import java.util.List;
     
    472473            }
    473474
    474             DateFormat dtf = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);
    475             // Make sure date/time format includes milliseconds
    476             if (dtf instanceof SimpleDateFormat) {
    477                 String pattern = ((SimpleDateFormat) dtf).toPattern();
    478                 if (!pattern.contains(".SSS")) {
    479                     dtf = new SimpleDateFormat(pattern.replace(":ss", ":ss.SSS"));
    480                 }
    481             }
    482             // Set timezone to UTC since UTC is assumed when parsing the EXIF timestamp,
    483             // see see org.openstreetmap.josm.tools.ExifReader.readTime(com.drew.metadata.Metadata)
    484             dtf.setTimeZone(DateUtils.UTC);
     475            DateTimeFormatter dtf = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.MEDIUM)
     476                    // Set timezone to UTC since UTC is assumed when parsing the EXIF timestamp,
     477                    // see see org.openstreetmap.josm.tools.ExifReader.readTime(com.drew.metadata.Metadata)
     478                    .withZone(ZoneOffset.UTC);
    485479
    486480            if (entry.hasExifTime()) {
    487                 osd.append(tr("\nEXIF time: {0}", dtf.format(entry.getExifTime())));
     481                osd.append(tr("\nEXIF time: {0}", dtf.format(entry.getExifInstant())));
    488482            }
    489483            if (entry.hasGpsTime()) {
    490                 osd.append(tr("\nGPS time: {0}", dtf.format(entry.getGpsTime())));
     484                osd.append(tr("\nGPS time: {0}", dtf.format(entry.getGpsInstant())));
    491485            }
    492486            Optional.ofNullable(entry.getIptcCaption()).map(s -> tr("\nCaption: {0}", s)).ifPresent(osd::append);
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java

    r17321 r17715  
    1313import java.awt.event.MouseEvent;
    1414import java.awt.event.MouseListener;
     15import java.time.Instant;
    1516import java.util.Arrays;
    1617import java.util.Comparator;
     
    8889            String name = (String) Optional.ofNullable(attr.get(GpxConstants.GPX_NAME)).orElse("");
    8990            String desc = (String) Optional.ofNullable(attr.get(GpxConstants.GPX_DESC)).orElse("");
    90             Date[] time = GpxData.getMinMaxTimeForTrack(trk);
     91            Instant[] time = GpxData.getMinMaxTimeForTrack(trk);
    9192            String url = (String) Optional.ofNullable(attr.get("url")).orElse("");
    9293            tracks[i] = new Object[]{name, desc, time, trk.length(), url, trk};
     
    140141        t.setRowSorter(rowSorter);
    141142        rowSorter.setModel(model);
    142         rowSorter.setComparator(2, Comparator.comparing((Date[] d) -> d == null ? Long.MIN_VALUE : d[0].getTime()));
     143        rowSorter.setComparator(2, Comparator.comparing((Instant[] d) -> d == null ? Instant.MIN : d[0]));
    143144        rowSorter.setComparator(3, Comparator.comparingDouble(length -> (double) length));
    144145        // default column widths
     
    150151            public Component getTableCellRendererComponent(
    151152                    JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    152                 if (value instanceof Date[]) {
    153                     value = GpxLayer.formatTimespan(((Date[]) value));
     153                if (value instanceof Instant[]) {
     154                    value = GpxLayer.formatTimespan(((Instant[]) value));
    154155                }
    155156                return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertFromGpxLayerAction.java

    r17586 r17715  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.ActionListener;
     9import java.time.Instant;
    910import java.util.ArrayList;
    1011import java.util.Date;
     
    3637import org.openstreetmap.josm.spi.preferences.Config;
    3738import org.openstreetmap.josm.tools.GBC;
    38 import org.openstreetmap.josm.tools.date.DateUtils;
    3939
    4040/**
     
    123123            String key = entry.getKey();
    124124            Object obj = entry.getValue();
    125             if (check && !keys.contains(key) && (obj instanceof String || obj instanceof Number || obj instanceof Date)) {
     125            if (check && !keys.contains(key) && (obj instanceof String || obj instanceof Number || obj instanceof Instant)) {
    126126                keys.add(key);
    127127            }
     
    129129                // only convert when required
    130130                p.put(GpxConstants.GPX_PREFIX + key, obj.toString());
    131             } else if (obj instanceof Date && GpxConstants.PT_TIME.equals(key)) {
     131            } else if (obj instanceof Instant && GpxConstants.PT_TIME.equals(key)) {
    132132                // timestamps should always be converted
    133                 Date date = (Date) obj;
     133                Instant date = (Instant) obj;
    134134                if (!none) { //... but the tag will only be set when required
    135                     p.put(GpxConstants.GPX_PREFIX + key, DateUtils.fromDate(date));
    136                 }
    137                 p.setTimestamp(date);
     135                    p.put(GpxConstants.GPX_PREFIX + key, String.valueOf(date));
     136                }
     137                p.setTimestamp(Date.from(date));
    138138            }
    139139        }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DateFilterPanel.java

    r16553 r17715  
    77import java.awt.GridBagLayout;
    88import java.awt.event.ActionListener;
     9import java.time.Instant;
    910import java.time.ZoneId;
    1011import java.time.ZonedDateTime;
     
    5253
    5354        final Date startTime, endTime;
    54         Date[] bounds = layer.data.getMinMaxTimeForAllTracks();
    55         startTime = (bounds.length == 0) ? Date.from(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()).toInstant()) : bounds[0];
    56         endTime = (bounds.length == 0) ? new Date() : bounds[1];
     55        Instant[] bounds = layer.data.getMinMaxTimeForAllTracks();
     56        if (bounds.length == 0) {
     57            startTime = Date.from(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()).toInstant());
     58            endTime = new Date();
     59        } else {
     60            startTime = Date.from(bounds[0]);
     61            endTime = Date.from(bounds[1]);
     62        }
    5763
    5864        dateFrom.setDate(startTime);
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r16913 r17715  
    2222import java.io.BufferedReader;
    2323import java.io.IOException;
     24import java.time.Instant;
    2425import java.util.ArrayList;
    2526import java.util.Arrays;
    2627import java.util.Collections;
    27 import java.util.Date;
    2828import java.util.LinkedList;
    2929import java.util.List;
     
    565565        double now = System.currentTimeMillis()/1000.0;
    566566        if (colored == ColorMode.TIME) {
    567             Date[] bounds = data.getMinMaxTimeForAllTracks();
     567            Instant[] bounds = data.getMinMaxTimeForAllTracks();
    568568            if (bounds.length >= 2) {
    569                 minval = bounds[0].getTime()/1000.0;
    570                 maxval = bounds[1].getTime()/1000.0;
     569                minval = bounds[0].getEpochSecond();
     570                maxval = bounds[1].getEpochSecond();
    571571            } else {
    572572                minval = 0;
  • trunk/src/org/openstreetmap/josm/io/nmea/NmeaReader.java

    r16643 r17715  
    366366                    // As this sentence has no complete time only use it
    367367                    // if there is no time so far
    368                     currentwp.setTime(d);
     368                    currentwp.setInstant(d.toInstant());
    369369                }
    370370                // elevation
     
    494494                }
    495495                // time: this sentence has complete time so always use it.
    496                 currentwp.setTime(d);
     496                currentwp.setInstant(d.toInstant());
    497497                // speed
    498498                accu = e[RMC.SPEED.position];
     
    544544            if (ps.pWp != currentwp) {
    545545                if (ps.pWp != null) {
    546                     ps.pWp.getDate();
     546                    ps.pWp.getInstant();
    547547                }
    548548                ps.pWp = currentwp;
  • trunk/src/org/openstreetmap/josm/io/rtklib/RtkLibPosReader.java

    r16643 r17715  
    9191                                    Double.parseDouble(fields[IDX_LON])));
    9292                            currentwp.put(GpxConstants.PT_ELE, fields[IDX_HEIGHT]);
    93                             currentwp.setTime(parseDate(fields[IDX_DATE]+" "+fields[IDX_TIME]));
     93                            currentwp.setInstant(parseDate(fields[IDX_DATE]+" "+fields[IDX_TIME]).toInstant());
    9494                            currentwp.put(GpxConstants.RTKLIB_Q, Integer.parseInt(fields[IDX_Q]));
    9595                            currentwp.put(GpxConstants.PT_SAT, fields[IDX_NS]);
  • trunk/src/org/openstreetmap/josm/io/session/GeoImageSessionExporter.java

    r14741 r17715  
    8787            }
    8888            if (entry.hasGpsTime()) {
    89                 addAttr("gps-time", Long.toString(entry.getGpsTime().getTime()), imgElem, support);
     89                addAttr("gps-time", Long.toString(entry.getGpsInstant().toEpochMilli()), imgElem, support);
    9090            }
    9191            if (entry.getExifOrientation() != null) {
     
    9393            }
    9494            if (entry.hasExifTime()) {
    95                 addAttr("exif-time", Long.toString(entry.getExifTime().getTime()), imgElem, support);
     95                addAttr("exif-time", Long.toString(entry.getExifInstant().toEpochMilli()), imgElem, support);
    9696            }
    9797            if (entry.hasExifGpsTime()) {
    98                 addAttr("exif-gps-time", Long.toString(entry.getExifGpsTime().getTime()), imgElem, support);
     98                addAttr("exif-gps-time", Long.toString(entry.getExifGpsInstant().toEpochMilli()), imgElem, support);
    9999            }
    100100            if (entry.getExifCoor() != null) {
  • trunk/src/org/openstreetmap/josm/io/session/GeoImageSessionImporter.java

    r14205 r17715  
    66import java.io.File;
    77import java.io.IOException;
     8import java.time.Instant;
    89import java.util.ArrayList;
    9 import java.util.Date;
    1010import java.util.List;
    1111
     
    9090                break;
    9191            case "gps-time":
    92                 entry.setGpsTime(new Date(Long.parseLong(attrElem.getTextContent())));
     92                entry.setGpsTime(Instant.ofEpochMilli(Long.parseLong(attrElem.getTextContent())));
    9393                break;
    9494            case "exif-orientation":
     
    9696                break;
    9797            case "exif-time":
    98                 entry.setExifTime(new Date(Long.parseLong(attrElem.getTextContent())));
     98                entry.setExifTime(Instant.ofEpochMilli(Long.parseLong(attrElem.getTextContent())));
    9999                break;
    100100            case "exif-gps-time":
    101                 entry.setExifGpsTime(new Date(Long.parseLong(attrElem.getTextContent())));
     101                entry.setExifGpsTime(Instant.ofEpochMilli(Long.parseLong(attrElem.getTextContent())));
    102102                break;
    103103            case "exif-coordinates":
  • 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'");
  • trunk/test/unit/org/openstreetmap/josm/data/ImageDataTest.java

    r17310 r17715  
    88
    99import java.io.File;
     10import java.time.Instant;
    1011import java.util.ArrayList;
    1112import java.util.Arrays;
    1213import java.util.Collections;
    13 import java.util.Date;
    1414import java.util.List;
    1515
     
    2828class ImageDataTest {
    2929
    30     private static ImageEntry newImageEntry(String file, Date exifTime) {
     30    private static ImageEntry newImageEntry(String file, Instant exifTime) {
    3131        ImageEntry entry = new ImageEntry(new File(file));
    3232        entry.setExifTime(exifTime);
     
    6565    @Test
    6666    void testSortData() {
    67         ImageEntry entry1 = newImageEntry("test1", new Date(1_000_000));
    68         ImageEntry entry2 = newImageEntry("test2", new Date(2_000_000));
     67        ImageEntry entry1 = newImageEntry("test1", Instant.ofEpochMilli(1_000_000));
     68        ImageEntry entry2 = newImageEntry("test2", Instant.ofEpochMilli(2_000_000));
    6969
    7070        ArrayList<ImageEntry> list = new ArrayList<>();
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java

    r17275 r17715  
    1010
    1111import java.io.IOException;
     12import java.time.Instant;
    1213import java.util.ArrayList;
    1314import java.util.Arrays;
     
    337338        WayPoint p4 = new WayPoint(LatLon.NORTH_POLE);
    338339        WayPoint p5 = new WayPoint(LatLon.NORTH_POLE);
    339         p1.setTime(new Date(200020));
    340         p2.setTime(new Date(100020));
    341         p4.setTime(new Date(500020));
     340        p1.setInstant(new Date(200020).toInstant());
     341        p2.setInstant(new Date(100020).toInstant());
     342        p4.setInstant(new Date(500020).toInstant());
    342343        data.addTrack(new GpxTrack(Arrays.asList(Arrays.asList(p1, p2)), Collections.emptyMap()));
    343344        data.addTrack(new GpxTrack(Arrays.asList(Arrays.asList(p3, p4, p5)), Collections.emptyMap()));
    344345
    345         Date[] times = data.getMinMaxTimeForAllTracks();
     346        Instant[] times = data.getMinMaxTimeForAllTracks();
    346347        assertEquals(times.length, 2);
    347         assertEquals(new Date(100020), times[0]);
    348         assertEquals(new Date(500020), times[1]);
     348        assertEquals(Instant.ofEpochMilli(100020), times[0]);
     349        assertEquals(Instant.ofEpochMilli(500020), times[1]);
    349350    }
    350351
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxImageCorrelationTest.java

    r17275 r17715  
    5858
    5959        final GpxImageEntry ib = new GpxImageEntry();
    60         ib.setExifTime(DateUtils.fromString("2016:01:03 11:54:58")); // 5 minutes before start of GPX
     60        ib.setExifTime(DateUtils.parseInstant("2016:01:03 11:54:58")); // 5 minutes before start of GPX
    6161        ib.createTmp();
    6262        final GpxImageEntry i0 = new GpxImageEntry();
    63         i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
     63        i0.setExifTime(DateUtils.parseInstant("2016:01:03 11:59:54")); // 4 sec before start of GPX
    6464        i0.createTmp();
    6565        final GpxImageEntry i1 = new GpxImageEntry();
    66         i1.setExifTime(DateUtils.fromString("2016:01:03 12:04:01"));
     66        i1.setExifTime(DateUtils.parseInstant("2016:01:03 12:04:01"));
    6767        i1.createTmp();
    6868        final GpxImageEntry i2 = new GpxImageEntry();
    69         i2.setExifTime(DateUtils.fromString("2016:01:03 12:04:57"));
     69        i2.setExifTime(DateUtils.parseInstant("2016:01:03 12:04:57"));
    7070        i2.createTmp();
    7171        final GpxImageEntry i3 = new GpxImageEntry();
    72         i3.setExifTime(DateUtils.fromString("2016:01:03 12:05:05"));
     72        i3.setExifTime(DateUtils.parseInstant("2016:01:03 12:05:05"));
    7373        i3.createTmp();
    7474        final GpxImageEntry i4 = new GpxImageEntry(); //Image close to two points with elevation, but without time
    75         i4.setExifTime(DateUtils.fromString("2016:01:03 12:05:20"));
     75        i4.setExifTime(DateUtils.parseInstant("2016:01:03 12:05:20"));
    7676        i4.createTmp();
    7777        final GpxImageEntry i5 = new GpxImageEntry(); //between two tracks, closer to first
    78         i5.setExifTime(DateUtils.fromString("2016:01:03 12:07:00"));
     78        i5.setExifTime(DateUtils.parseInstant("2016:01:03 12:07:00"));
    7979        i5.createTmp();
    8080        final GpxImageEntry i6 = new GpxImageEntry(); //between two tracks, closer to second (more than 1 minute from any track)
    81         i6.setExifTime(DateUtils.fromString("2016:01:03 12:07:45"));
     81        i6.setExifTime(DateUtils.parseInstant("2016:01:03 12:07:45"));
    8282        i6.createTmp();
    8383
     
    119119        assertEquals(null, i6.getElevation());
    120120
    121         assertEquals(null, ib.getGpsTime());
    122         assertEquals(DateUtils.fromString("2016:01:03 11:59:54"), i0.getGpsTime()); // original time is kept
    123         assertEquals(DateUtils.fromString("2016:01:03 12:04:01"), i1.getGpsTime());
    124         assertEquals(DateUtils.fromString("2016:01:03 12:04:57"), i2.getGpsTime());
    125         assertEquals(DateUtils.fromString("2016:01:03 12:05:05"), i3.getGpsTime());
     121        assertEquals(null, ib.getGpsInstant());
     122        assertEquals(DateUtils.parseInstant("2016:01:03 11:59:54"), i0.getGpsInstant()); // original time is kept
     123        assertEquals(DateUtils.parseInstant("2016:01:03 12:04:01"), i1.getGpsInstant());
     124        assertEquals(DateUtils.parseInstant("2016:01:03 12:04:57"), i2.getGpsInstant());
     125        assertEquals(DateUtils.parseInstant("2016:01:03 12:05:05"), i3.getGpsInstant());
    126126
    127127        clearTmp(images);
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/WayPointTest.java

    r17275 r17715  
    55import org.junit.jupiter.api.Test;
    66import org.openstreetmap.josm.TestUtils;
     7import org.openstreetmap.josm.data.coor.LatLon;
    78import org.openstreetmap.josm.testutils.JOSMTestRules;
    89
     
    1011import nl.jqno.equalsverifier.EqualsVerifier;
    1112import nl.jqno.equalsverifier.Warning;
     13
     14import java.time.Instant;
     15
     16import static org.junit.jupiter.api.Assertions.assertEquals;
     17import static org.junit.jupiter.api.Assertions.assertNotEquals;
    1218
    1319/**
     
    3743            .verify();
    3844    }
     45
     46    /**
     47     * Unit test of copy constructor {@link WayPoint#WayPoint(WayPoint)}
     48     */
     49    @Test
     50    void testConstructor() {
     51        WayPoint wp1 = new WayPoint(new LatLon(12., 34.));
     52        wp1.setInstant(Instant.ofEpochMilli(123_456_789));
     53        WayPoint wp2 = new WayPoint(wp1);
     54        assertEquals(wp1, wp2);
     55        assertEquals(wp1.getInstant(), wp2.getInstant());
     56        wp2.setInstant(Instant.ofEpochMilli(234_456_789));
     57        assertNotEquals(wp1, wp2);
     58        assertNotEquals(wp1.getInstant(), wp2.getInstant());
     59    }
    3960}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java

    r17275 r17715  
    1010import java.io.File;
    1111import java.nio.charset.StandardCharsets;
    12 import java.text.DateFormat;
    1312import java.util.Collection;
    1413import java.util.Collections;
     
    3938import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
    4039import org.openstreetmap.josm.tools.Logging;
    41 import org.openstreetmap.josm.tools.date.DateUtils;
    4240
    4341import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    245243        assertEquals(3, trackpoints.size());
    246244        Iterator<WayPoint> it = trackpoints.iterator();
    247         DateFormat gpxFormat = DateUtils.getGpxFormat();
    248245        WayPoint p1 = it.next();
    249246        assertEquals(new LatLon(47.0, 9.0), p1.getCoor());
    250247        assertEquals("123", p1.get(GpxConstants.PT_ELE));
    251         assertEquals("2018-08-01T10:00:00.000Z", gpxFormat.format(p1.get(GpxConstants.PT_TIME)));
     248        assertEquals("2018-08-01T10:00:00Z", String.valueOf(p1.get(GpxConstants.PT_TIME)));
    252249        WayPoint p2 = it.next();
    253250        assertEquals(new LatLon(47.1, 9.1), p2.getCoor());
    254251        assertEquals("456", p2.get(GpxConstants.PT_ELE));
    255         assertEquals("2018-08-01T10:01:00.000Z", gpxFormat.format(p2.get(GpxConstants.PT_TIME)));
     252        assertEquals("2018-08-01T10:01:00Z", String.valueOf(p2.get(GpxConstants.PT_TIME)));
    256253        WayPoint p3 = it.next();
    257254        assertEquals(new LatLon(47.05, 9.05), p3.getCoor());
    258255        assertEquals("789", p3.get(GpxConstants.PT_ELE));
    259         assertEquals("2018-08-01T10:02:00.000Z", gpxFormat.format(p3.get(GpxConstants.PT_TIME)));
     256        assertEquals("2018-08-01T10:02:00Z", String.valueOf(p3.get(GpxConstants.PT_TIME)));
    260257    }
    261258
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImagesTest.java

    r17275 r17715  
    4848        final GpxData gpx = GpxReaderTest.parseGpxData("nodist/data/2094047.gpx");
    4949        final ImageEntry i0 = new ImageEntry();
    50         i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
     50        i0.setExifTime(DateUtils.parseInstant("2016:01:03 11:59:54")); // 4 sec before start of GPX
    5151        i0.createTmp();
    5252        assertEquals(Pair.create(GpxTimezone.ZERO, GpxTimeOffset.seconds(-4)),
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/ImageEntryTest.java

    r17580 r17715  
    2727        ImageEntry e = new ImageEntry(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG")));
    2828        e.extractExif();
    29         assertNotNull(e.getExifTime());
     29        assertNotNull(e.getExifInstant());
    3030    }
    3131
  • trunk/test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java

    r17275 r17715  
    1111import java.nio.file.Files;
    1212import java.nio.file.Paths;
    13 import java.text.SimpleDateFormat;
     13import java.time.Instant;
    1414import java.util.ArrayList;
    15 import java.util.Date;
    1615import java.util.List;
    1716import java.util.TimeZone;
    1817
    19 import org.junit.jupiter.api.BeforeEach;
    2018import org.junit.jupiter.api.Test;
    2119import org.junit.jupiter.api.extension.RegisterExtension;
     
    4543    public JOSMTestRules test = new JOSMTestRules();
    4644
    47     private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    48 
    49     /**
    50      * Forces the timezone.
    51      */
    52     @BeforeEach
    53     public void setUp() {
    54         iso8601.setTimeZone(DateUtils.UTC);
    55     }
    56 
    5745    /**
    5846     * Tests reading a nmea file.
     
    6856
    6957        final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints());
    70         assertEquals(DateUtils.fromString("2016-01-25T05:05:09.200Z"), wayPoints.get(0).get(GpxConstants.PT_TIME));
    71         assertEquals(DateUtils.fromString("2016-01-25T05:05:09.400Z"), wayPoints.get(1).get(GpxConstants.PT_TIME));
    72         assertEquals(DateUtils.fromString("2016-01-25T05:05:09.600Z"), wayPoints.get(2).get(GpxConstants.PT_TIME));
    73         assertEquals(wayPoints.get(0).getDate(), wayPoints.get(0).get(GpxConstants.PT_TIME));
     58        assertEquals(DateUtils.parseInstant("2016-01-25T05:05:09.200Z"), wayPoints.get(0).get(GpxConstants.PT_TIME));
     59        assertEquals(DateUtils.parseInstant("2016-01-25T05:05:09.400Z"), wayPoints.get(1).get(GpxConstants.PT_TIME));
     60        assertEquals(DateUtils.parseInstant("2016-01-25T05:05:09.600Z"), wayPoints.get(2).get(GpxConstants.PT_TIME));
     61        assertEquals(wayPoints.get(0).getInstant(), wayPoints.get(0).get(GpxConstants.PT_TIME));
    7462
    75         assertEquals("2016-01-25T05:05:09.200Z", iso8601.format(wayPoints.get(0).getDate()));
    76         assertEquals("2016-01-25T05:05:09.400Z", iso8601.format(wayPoints.get(1).getDate()));
    77         assertEquals("2016-01-25T05:05:09.600Z", iso8601.format(wayPoints.get(2).getDate()));
     63        assertEquals(DateUtils.parseInstant("2016-01-25T05:05:09.200Z"), wayPoints.get(0).getInstant());
     64        assertEquals(DateUtils.parseInstant("2016-01-25T05:05:09.400Z"), wayPoints.get(1).getInstant());
     65        assertEquals(DateUtils.parseInstant("2016-01-25T05:05:09.600Z"), wayPoints.get(2).getInstant());
    7866
    7967        assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor());
     
    171159    }
    172160
    173     private static Date readDate(String nmeaLine) throws IOException, SAXException {
    174         return readWayPoint(nmeaLine).getDate();
     161    private static Instant readDate(String nmeaLine) throws IOException, SAXException {
     162        return readWayPoint(nmeaLine).getInstant();
    175163    }
    176164
     
    185173    @Test
    186174    void testTicket16496() throws Exception {
    187         assertEquals("2018-05-30T16:28:59.400Z", iso8601.format(
    188                 readDate("$GNRMC,162859.400,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*13")));
    189         assertEquals("2018-05-30T16:28:59.400Z", iso8601.format(
    190                 readDate("$GNRMC,162859.40,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*23")));
    191         assertEquals("2018-05-30T16:28:59.400Z", iso8601.format(
    192                 readDate("$GNRMC,162859.4,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*13")));
     175        assertEquals(DateUtils.parseInstant("2018-05-30T16:28:59.400Z"),
     176                readDate("$GNRMC,162859.400,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*13"));
     177        assertEquals(DateUtils.parseInstant("2018-05-30T16:28:59.400Z"),
     178                readDate("$GNRMC,162859.40,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*23"));
     179        assertEquals(DateUtils.parseInstant("2018-05-30T16:28:59.400Z"),
     180                readDate("$GNRMC,162859.4,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*13"));
    193181    }
    194182
  • trunk/test/unit/org/openstreetmap/josm/io/rtklib/RtkLibPosReaderTest.java

    r17275 r17715  
    77import java.nio.file.Files;
    88import java.nio.file.Paths;
    9 import java.text.SimpleDateFormat;
     9import java.time.Instant;
    1010import java.util.ArrayList;
    1111import java.util.List;
    1212import java.util.TimeZone;
    1313
    14 import org.junit.jupiter.api.BeforeEach;
    1514import org.junit.jupiter.api.Test;
    1615import org.junit.jupiter.api.extension.RegisterExtension;
     
    3534    public JOSMTestRules test = new JOSMTestRules();
    3635
    37     private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    38 
    39     /**
    40      * Forces the timezone.
    41      */
    42     @BeforeEach
    43     public void setUp() {
    44         iso8601.setTimeZone(DateUtils.UTC);
    45     }
    46 
    4736    private static RtkLibPosReader read(String path) throws IOException, SAXException {
    4837        TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
     
    6251
    6352        List<WayPoint> wayPoints = new ArrayList<>(in.getGpxData().tracks.iterator().next().getSegments().iterator().next().getWayPoints());
    64         assertEquals(DateUtils.fromString("2019-06-08T08:23:12.000Z"), wayPoints.get(0).get(GpxConstants.PT_TIME));
    65         assertEquals(DateUtils.fromString("2019-06-08T08:23:12.300Z"), wayPoints.get(1).get(GpxConstants.PT_TIME));
    66         assertEquals(DateUtils.fromString("2019-06-08T08:23:12.600Z"), wayPoints.get(2).get(GpxConstants.PT_TIME));
    67         assertEquals(wayPoints.get(0).getDate(), wayPoints.get(0).get(GpxConstants.PT_TIME));
     53        assertEquals(DateUtils.parseInstant("2019-06-08T08:23:12.000Z"), wayPoints.get(0).get(GpxConstants.PT_TIME));
     54        assertEquals(DateUtils.parseInstant("2019-06-08T08:23:12.300Z"), wayPoints.get(1).get(GpxConstants.PT_TIME));
     55        assertEquals(DateUtils.parseInstant("2019-06-08T08:23:12.600Z"), wayPoints.get(2).get(GpxConstants.PT_TIME));
     56        assertEquals(wayPoints.get(0).getInstant(), wayPoints.get(0).get(GpxConstants.PT_TIME));
    6857
    69         assertEquals("2019-06-08T08:23:12.000Z", iso8601.format(wayPoints.get(0).getDate()));
    70         assertEquals("2019-06-08T08:23:12.300Z", iso8601.format(wayPoints.get(1).getDate()));
    71         assertEquals("2019-06-08T08:23:12.600Z", iso8601.format(wayPoints.get(2).getDate()));
     58        assertEquals(Instant.parse("2019-06-08T08:23:12.000Z"), wayPoints.get(0).getInstant());
     59        assertEquals(Instant.parse("2019-06-08T08:23:12.300Z"), wayPoints.get(1).getInstant());
     60        assertEquals(Instant.parse("2019-06-08T08:23:12.600Z"), wayPoints.get(2).getInstant());
    7261
    7362        assertEquals(new LatLon(46.948881673, -1.484757046), wayPoints.get(0).getCoor());
  • trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java

    r17275 r17715  
    88import java.io.IOException;
    99import java.text.DecimalFormat;
    10 import java.text.ParseException;
    11 import java.text.SimpleDateFormat;
    12 import java.util.Date;
     10import java.time.Instant;
    1311
    1412import org.junit.jupiter.api.BeforeEach;
     
    4846    /**
    4947     * Test time extraction
    50      * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
    5148     */
    5249    @Test
    53     void testReadTime() throws ParseException {
    54         Date date = ExifReader.readTime(directionSampleFile);
    55         doTest("2010-05-15T17:12:05.000", date);
     50    void testReadTime() {
     51        Instant date = ExifReader.readInstant(directionSampleFile);
     52        assertEquals(Instant.parse("2010-05-15T17:12:05.000Z"), date);
    5653    }
    5754
    5855    /**
    5956     * Tests reading sub-seconds from the EXIF header
    60      * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
    6157     */
    6258    @Test
    63     void testReadTimeSubSecond1() throws ParseException {
    64         Date date = ExifReader.readTime(new File("nodist/data/IMG_20150711_193419.jpg"));
    65         doTest("2015-07-11T19:34:19.100", date);
    66     }
    67 
    68     private static void doTest(String expectedDate, Date parsedDate) {
    69         assertEquals(expectedDate, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(parsedDate));
     59    void testReadTimeSubSecond1() {
     60        Instant date = ExifReader.readInstant(new File("nodist/data/IMG_20150711_193419.jpg"));
     61        assertEquals(Instant.parse("2015-07-11T19:34:19.100Z"), date);
    7062    }
    7163
    7264    private static void doTestFile(String expectedDate, int ticket, String filename) {
    73         doTest(expectedDate, ExifReader.readTime(new File(TestUtils.getRegressionDataFile(ticket, filename))));
     65        Instant date = ExifReader.readInstant(new File(TestUtils.getRegressionDataFile(ticket, filename)));
     66        assertEquals(Instant.parse(expectedDate), date);
    7467    }
    7568
     
    125118    @Test
    126119    void testTicket11685() throws IOException {
    127         doTestFile("2015-11-08T15:33:27.500", 11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg");
     120        doTestFile("2015-11-08T15:33:27.500Z", 11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg");
    128121    }
    129122
     
    134127    @Test
    135128    void testTicket14209() throws IOException {
    136         doTestFile("2017-01-16T18:27:00.000", 14209, "0MbEfj1S--.1.jpg");
    137         doTestFile("2016-08-13T19:51:13.000", 14209, "7VWFOryj--.1.jpg");
     129        doTestFile("2017-01-16T18:27:00.000Z", 14209, "0MbEfj1S--.1.jpg");
     130        doTestFile("2016-08-13T19:51:13.000Z", 14209, "7VWFOryj--.1.jpg");
    138131    }
    139132}
Note: See TracChangeset for help on using the changeset viewer.