Changeset 19539 in josm for trunk/src


Ignore:
Timestamp:
2026-02-20T22:21:27+01:00 (3 days ago)
Author:
stoecker
Message:

see #24635 - remove usage of Date

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/widgets/DateEditorWithSlider.java

    r17842 r19539  
    2727 * @since 5815
    2828 */
     29@SuppressWarnings("PMD.ReplaceJavaUtilDate") // JSpinner needs Date anyway, so not using Date makes no sense
    2930public class DateEditorWithSlider extends JPanel {
    3031    private final JSpinner spinner;
  • trunk/src/org/openstreetmap/josm/io/nmea/NmeaParser.java

    r19519 r19539  
    33
    44import java.nio.charset.StandardCharsets;
    5 import java.text.ParsePosition;
    6 import java.text.SimpleDateFormat;
    75import java.time.Instant;
     6import java.time.ZoneOffset;
     7import java.time.format.DateTimeFormatter;
     8import java.time.format.DateTimeFormatterBuilder;
     9import java.time.format.DateTimeParseException;
     10import java.time.format.ResolverStyle;
     11import java.time.temporal.ChronoField;
    812import java.util.ArrayList;
    913import java.util.Arrays;
    1014import java.util.Collection;
    1115import java.util.Collections;
    12 import java.util.Date;
    1316import java.util.Locale;
    14 import java.util.regex.Matcher;
    15 import java.util.regex.Pattern;
    1617
    1718import org.openstreetmap.josm.data.coor.LatLon;
     
    2021import org.openstreetmap.josm.io.IllegalDataException;
    2122import org.openstreetmap.josm.tools.Logging;
    22 import org.openstreetmap.josm.tools.date.DateUtils;
    2323
    2424/**
     
    180180    }
    181181
    182     private static final Pattern DATE_TIME_PATTERN = Pattern.compile("(\\d{12})(\\.\\d+)?");
    183 
    184     private final SimpleDateFormat rmcTimeFmt = new SimpleDateFormat("ddMMyyHHmmss.SSS", Locale.ENGLISH);
    185 
    186     private Instant readTime(String p) throws IllegalDataException {
    187         // NMEA defines time with "a variable number of digits for decimal-fraction of seconds"
    188         // This variable decimal fraction cannot be parsed by SimpleDateFormat
    189         Matcher m = DATE_TIME_PATTERN.matcher(p);
    190         if (m.matches()) {
    191             String date = m.group(1);
    192             double milliseconds = 0d;
    193             if (m.groupCount() > 1 && m.group(2) != null) {
    194                 milliseconds = 1000d * Double.parseDouble("0" + m.group(2));
    195             }
    196             // Add milliseconds on three digits to match SimpleDateFormat pattern
    197             date += String.format(".%03d", (int) milliseconds);
    198             Date d = rmcTimeFmt.parse(date, new ParsePosition(0));
    199             if (d != null)
    200                 return d.toInstant();
    201         }
    202         throw new IllegalDataException("Date is malformed: '" + p + "'");
    203     }
     182    /**
     183     * NMEA defines time with "a variable number of digits for decimal-fraction of seconds"
     184     */
     185    private static final DateTimeFormatter RMC_TIME_FMT =
     186        new DateTimeFormatterBuilder()
     187                .appendPattern("ddMMyyHHmmss")
     188                .optionalStart()
     189                .appendFraction(ChronoField.NANO_OF_SECOND, 1, 9, true)
     190                .optionalEnd()
     191                .toFormatter(Locale.ENGLISH)
     192                .withZone(ZoneOffset.UTC)
     193                /* allow bad date information, we're mainly interested in the positions */
     194                .withResolverStyle(ResolverStyle.LENIENT);
    204195
    205196    protected Collection<WayPoint> waypoints = new ArrayList<>();
     
    291282     */
    292283    public NmeaParser() {
    293         rmcTimeFmt.setTimeZone(DateUtils.UTC);
    294284        pDate = "010100"; // TODO date problem
    295285    }
     
    366356                // time
    367357                accu = e[GGA.TIME.position];
    368                 Instant instant = readTime(currentDate+accu);
     358                Instant instant = Instant.from(RMC_TIME_FMT.parse(currentDate+accu));
    369359
    370360                if ((pTime == null) || (currentwp == null) || !pTime.equals(accu)) {
     
    523513                String time = e[RMC.TIME.position];
    524514
    525                 Instant instant = readTime(currentDate+time);
     515                Instant instant = Instant.from(RMC_TIME_FMT.parse(currentDate+time));
    526516
    527517                if (pTime == null || currentwp == null || !pTime.equals(time)) {
     
    590580            return true;
    591581
    592         } catch (IllegalArgumentException | IndexOutOfBoundsException | IllegalDataException ex) {
     582        } catch (IllegalArgumentException | IndexOutOfBoundsException | IllegalDataException | DateTimeParseException ex) {
    593583            if (malformed < 5) {
    594584                Logging.warn(ex);
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java

    r19425 r19539  
    1111import java.nio.charset.Charset;
    1212import java.nio.charset.StandardCharsets;
     13import java.time.ZoneOffset;
     14import java.time.ZonedDateTime;
     15import java.time.format.DateTimeFormatter;
    1316import java.util.Collection;
    14 import java.util.Date;
    1517import java.util.HashMap;
    1618import java.util.Locale;
     
    453455            boolean endHeaders) throws IOException {
    454456        out.write("HTTP/1.1 " + status + "\r\n");
    455         out.write("Date: " + new Date() + "\r\n");
     457        out.write("Date: " + DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneOffset.UTC)) + "\r\n");
    456458        out.write("Server: " + JOSM_REMOTE_CONTROL + "\r\n");
    457459        out.write("Content-type: " + contentType + "; charset=" + RESPONSE_CHARSET.name().toLowerCase(Locale.ENGLISH) + "\r\n");
  • trunk/src/org/openstreetmap/josm/tools/ColorScale.java

    r19238 r19539  
    99import java.awt.Font;
    1010import java.util.Arrays;
    11 import java.util.Date;
    1211import java.time.ZoneId;
    1312import java.time.Instant;
     
    489488            } else {
    490489                final double val = minVal + i * (maxVal - minVal) / intervalCount;
    491                 final long longval = (long) val;
    492 
    493                 final Date date = new Date(longval * 1000L);
    494                 final Instant dateInst = date.toInstant();
     490                final Instant dateInst = Instant.ofEpochSecond((long) val);
    495491
    496492                final ZoneId gmt = ZoneId.of("GMT");
Note: See TracChangeset for help on using the changeset viewer.