- Timestamp:
- 2026-02-20T22:21:27+01:00 (3 days ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
-
gui/widgets/DateEditorWithSlider.java (modified) (1 diff)
-
io/nmea/NmeaParser.java (modified) (7 diffs)
-
io/remotecontrol/RequestProcessor.java (modified) (2 diffs)
-
tools/ColorScale.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/widgets/DateEditorWithSlider.java
r17842 r19539 27 27 * @since 5815 28 28 */ 29 @SuppressWarnings("PMD.ReplaceJavaUtilDate") // JSpinner needs Date anyway, so not using Date makes no sense 29 30 public class DateEditorWithSlider extends JPanel { 30 31 private final JSpinner spinner; -
trunk/src/org/openstreetmap/josm/io/nmea/NmeaParser.java
r19519 r19539 3 3 4 4 import java.nio.charset.StandardCharsets; 5 import java.text.ParsePosition;6 import java.text.SimpleDateFormat;7 5 import java.time.Instant; 6 import java.time.ZoneOffset; 7 import java.time.format.DateTimeFormatter; 8 import java.time.format.DateTimeFormatterBuilder; 9 import java.time.format.DateTimeParseException; 10 import java.time.format.ResolverStyle; 11 import java.time.temporal.ChronoField; 8 12 import java.util.ArrayList; 9 13 import java.util.Arrays; 10 14 import java.util.Collection; 11 15 import java.util.Collections; 12 import java.util.Date;13 16 import java.util.Locale; 14 import java.util.regex.Matcher;15 import java.util.regex.Pattern;16 17 17 18 import org.openstreetmap.josm.data.coor.LatLon; … … 20 21 import org.openstreetmap.josm.io.IllegalDataException; 21 22 import org.openstreetmap.josm.tools.Logging; 22 import org.openstreetmap.josm.tools.date.DateUtils;23 23 24 24 /** … … 180 180 } 181 181 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); 204 195 205 196 protected Collection<WayPoint> waypoints = new ArrayList<>(); … … 291 282 */ 292 283 public NmeaParser() { 293 rmcTimeFmt.setTimeZone(DateUtils.UTC);294 284 pDate = "010100"; // TODO date problem 295 285 } … … 366 356 // time 367 357 accu = e[GGA.TIME.position]; 368 Instant instant = readTime(currentDate+accu);358 Instant instant = Instant.from(RMC_TIME_FMT.parse(currentDate+accu)); 369 359 370 360 if ((pTime == null) || (currentwp == null) || !pTime.equals(accu)) { … … 523 513 String time = e[RMC.TIME.position]; 524 514 525 Instant instant = readTime(currentDate+time);515 Instant instant = Instant.from(RMC_TIME_FMT.parse(currentDate+time)); 526 516 527 517 if (pTime == null || currentwp == null || !pTime.equals(time)) { … … 590 580 return true; 591 581 592 } catch (IllegalArgumentException | IndexOutOfBoundsException | IllegalDataException ex) { 582 } catch (IllegalArgumentException | IndexOutOfBoundsException | IllegalDataException | DateTimeParseException ex) { 593 583 if (malformed < 5) { 594 584 Logging.warn(ex); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
r19425 r19539 11 11 import java.nio.charset.Charset; 12 12 import java.nio.charset.StandardCharsets; 13 import java.time.ZoneOffset; 14 import java.time.ZonedDateTime; 15 import java.time.format.DateTimeFormatter; 13 16 import java.util.Collection; 14 import java.util.Date;15 17 import java.util.HashMap; 16 18 import java.util.Locale; … … 453 455 boolean endHeaders) throws IOException { 454 456 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"); 456 458 out.write("Server: " + JOSM_REMOTE_CONTROL + "\r\n"); 457 459 out.write("Content-type: " + contentType + "; charset=" + RESPONSE_CHARSET.name().toLowerCase(Locale.ENGLISH) + "\r\n"); -
trunk/src/org/openstreetmap/josm/tools/ColorScale.java
r19238 r19539 9 9 import java.awt.Font; 10 10 import java.util.Arrays; 11 import java.util.Date;12 11 import java.time.ZoneId; 13 12 import java.time.Instant; … … 489 488 } else { 490 489 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); 495 491 496 492 final ZoneId gmt = ZoneId.of("GMT");
Note:
See TracChangeset
for help on using the changeset viewer.
