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

see #14176 - Migrate GPX to Instant

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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++;
Note: See TracChangeset for help on using the changeset viewer.