Changeset 17715 in josm
- Timestamp:
- 2021-04-08T22:56:06+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r17439 r17715 4 4 import java.io.File; 5 5 import java.text.MessageFormat; 6 import java.time.Instant; 6 7 import java.util.ArrayList; 7 8 import java.util.Arrays; … … 9 10 import java.util.Collections; 10 11 import java.util.Comparator; 11 import java.util.Date;12 12 import java.util.HashMap; 13 13 import java.util.HashSet; … … 200 200 boolean split = false; 201 201 WayPoint prevLastOwnWp = null; 202 DateprevWpTime = null;202 Instant prevWpTime = null; 203 203 for (WayPoint wp : wpsOld) { 204 Date wpTime = wp.getDate();204 Instant wpTime = wp.getInstant(); 205 205 boolean overlap = false; 206 206 if (wpTime != null) { 207 207 for (GpxTrackSegmentSpan ownspan : getSegmentSpans()) { 208 if (wpTime. after(ownspan.firstTime) && wpTime.before(ownspan.lastTime)) {208 if (wpTime.isAfter(ownspan.firstTime) && wpTime.isBefore(ownspan.lastTime)) { 209 209 overlap = true; 210 210 if (connect) { … … 219 219 break; 220 220 } 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)) { 223 223 // the overlapping high priority track is shorter than the distance 224 224 // between two waypoints of the low priority track … … 287 287 static class GpxTrackSegmentSpan { 288 288 289 final DatefirstTime;290 final DatelastTime;289 final Instant firstTime; 290 final Instant lastTime; 291 291 private final boolean inv; 292 292 private final WayPoint firstWp; … … 294 294 295 295 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); 299 299 if (inv) { 300 300 firstWp = b; … … 333 333 334 334 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)); 337 337 } 338 338 … … 720 720 * @return minimum and maximum dates in array of 2 elements 721 721 */ 722 public static Date[] getMinMaxTimeForTrack(IGpxTrack trk) {722 public static Instant[] getMinMaxTimeForTrack(IGpxTrack trk) { 723 723 final LongSummaryStatistics statistics = trk.getSegments().stream() 724 724 .flatMap(seg -> seg.getWayPoints().stream()) … … 727 727 return statistics.getCount() == 0 || (statistics.getMin() == 0 && statistics.getMax() == 0) 728 728 ? null 729 : new Date[]{new Date(statistics.getMin()), new Date(statistics.getMax())};729 : new Instant[]{Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax())}; 730 730 } 731 731 … … 737 737 * @since 7319 738 738 */ 739 public synchronized Date[] getMinMaxTimeForAllTracks() {739 public synchronized Instant[] getMinMaxTimeForAllTracks() { 740 740 long now = System.currentTimeMillis(); 741 741 final LongSummaryStatistics statistics = tracks.stream() … … 746 746 .summaryStatistics(); 747 747 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())}; 750 750 } 751 751 -
trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java
r17579 r17715 3 3 4 4 import java.util.ArrayList; 5 import java.util.Date;6 5 import java.util.List; 7 6 import java.util.concurrent.TimeUnit; … … 226 225 final GpxImageEntry curImg = images.get(i); 227 226 final GpxImageEntry curTmp = curImg.getTmp(); 228 final long time = curImg.getExif Time().getTime();227 final long time = curImg.getExifInstant().toEpochMilli(); 229 228 if ((!isLast && time > curWpTime) || time < prevWpTime) { 230 229 break; … … 239 238 curTmp.setPos(curWp.getCoor()); 240 239 } 241 curTmp.setGpsTime( new Date(curImg.getExifTime().getTime() -offset));240 curTmp.setGpsTime(curImg.getExifInstant().minusMillis(offset)); 242 241 curTmp.flagNewGpsData(); 243 242 curImg.tmpUpdated(); … … 253 252 GpxImageEntry curImg = images.get(i); 254 253 GpxImageEntry curTmp = curImg.getTmp(); 255 final long imgTime = curImg.getExif Time().getTime();254 final long imgTime = curImg.getExifInstant().toEpochMilli(); 256 255 if (imgTime < prevWpTime) { 257 256 break; … … 265 264 curTmp.setElevation(prevElevation + (curElevation - prevElevation) * timeDiff); 266 265 } 267 curTmp.setGpsTime( new Date(curImg.getExifTime().getTime() -offset));266 curTmp.setGpsTime(curImg.getExifInstant().minusMillis(offset)); 268 267 curTmp.flagNewGpsData(); 269 268 curImg.tmpUpdated(); … … 281 280 282 281 // No photos or the first photo taken is later than the search period 283 if (lstSize == 0 || searchedTime < images.get(0).getExif Time().getTime())282 if (lstSize == 0 || searchedTime < images.get(0).getExifInstant().toEpochMilli()) 284 283 return -1; 285 284 286 285 // The search period is later than the last photo 287 if (searchedTime > images.get(lstSize - 1).getExif Time().getTime())286 if (searchedTime > images.get(lstSize - 1).getExifInstant().toEpochMilli()) 288 287 return lstSize-1; 289 288 … … 294 293 while (endIndex - startIndex > 1) { 295 294 curIndex = (endIndex + startIndex) / 2; 296 if (searchedTime > images.get(curIndex).getExif Time().getTime()) {295 if (searchedTime > images.get(curIndex).getExifInstant().toEpochMilli()) { 297 296 startIndex = curIndex; 298 297 } else { … … 300 299 } 301 300 } 302 if (searchedTime < images.get(endIndex).getExif Time().getTime())301 if (searchedTime < images.get(endIndex).getExifInstant().toEpochMilli()) 303 302 return startIndex; 304 303 305 304 // This final loop is to check if photos with the exact same EXIF time follows 306 while ((endIndex < (lstSize - 1)) && (images.get(endIndex).getExif Time().getTime()307 == images.get(endIndex + 1).getExif Time().getTime())) {305 while ((endIndex < (lstSize - 1)) && (images.get(endIndex).getExifInstant().toEpochMilli() 306 == images.get(endIndex + 1).getExifInstant().toEpochMilli())) { 308 307 endIndex++; 309 308 } -
trunk/src/org/openstreetmap/josm/data/gpx/GpxImageEntry.java
r17579 r17715 6 6 import java.io.File; 7 7 import java.io.IOException; 8 import java.time.Instant; 8 9 import java.util.Date; 9 10 import java.util.List; … … 43 44 private LatLon exifCoor; 44 45 private Double exifImgDir; 45 private DateexifTime;46 private Instant exifTime; 46 47 /** 47 48 * Flag isNewGpsData indicates that the GPS data of the image is new or has changed. … … 51 52 private boolean isNewGpsData; 52 53 /** Temporary source of GPS time if not correlated with GPX track. */ 53 private DateexifGpsTime;54 private Instant exifGpsTime; 54 55 55 56 private String iptcCaption; … … 68 69 private Double elevation; 69 70 /** The time after correlation with a gpx track */ 70 private DategpsTime;71 private Instant gpsTime; 71 72 72 73 private int width; … … 173 174 * is returned if that copy exists. 174 175 * @return the GPS time value 175 */ 176 * @deprecated Use {@link #getGpsInstant} 177 */ 178 @Deprecated 176 179 public Date getGpsTime() { 177 180 if (tmp != null) … … 181 184 182 185 /** 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 /** 183 195 * Convenient way to determine if this entry has a GPS time, without the cost of building a defensive copy. 184 196 * @return {@code true} if this entry has a GPS time … … 208 220 * Returns EXIF time 209 221 * @return EXIF time 210 */ 222 * @deprecated Use {@link #getExifInstant} 223 */ 224 @Deprecated 211 225 public Date getExifTime() { 212 226 return getDefensiveDate(exifTime); 227 } 228 229 /** 230 * Returns EXIF time 231 * @return EXIF time 232 */ 233 public Instant getExifInstant() { 234 return exifTime; 213 235 } 214 236 … … 226 248 * @return the EXIF GPS time 227 249 * @since 6392 228 */ 250 * @deprecated Use {@link #getExifGpsInstant} 251 */ 252 @Deprecated 229 253 public Date getExifGpsTime() { 230 254 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; 231 263 } 232 264 … … 240 272 } 241 273 242 private static Date getDefensiveDate( Datedate) {274 private static Date getDefensiveDate(Instant date) { 243 275 if (date == null) 244 276 return null; 245 return new Date(date.getTime());277 return Date.from(date); 246 278 } 247 279 … … 325 357 * Sets EXIF time. 326 358 * @param exifTime EXIF time 327 */ 359 * @deprecated Use {@link #setExifTime(Instant)} 360 */ 361 @Deprecated 328 362 public void setExifTime(Date exifTime) { 329 this.exifTime = getDefensiveDate(exifTime);363 this.exifTime = exifTime == null ? null : exifTime.toInstant(); 330 364 } 331 365 … … 334 368 * @param exifGpsTime the EXIF GPS time 335 369 * @since 6392 336 */ 370 * @deprecated Use {@link #setExifGpsTime(Instant)} 371 */ 372 @Deprecated 337 373 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 341 383 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; 343 409 } 344 410 … … 635 701 Logging.warn(topException); 636 702 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())); 638 704 setExifCoor(null); 639 705 setPos(null); … … 646 712 // Changed to silently cope with no time info in exif. One case 647 713 // of person having time that couldn't be parsed, but valid GPS info 648 Datetime = null;714 Instant time = null; 649 715 try { 650 time = ExifReader.read Time(metadata);716 time = ExifReader.readInstant(metadata); 651 717 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException ex) { 652 718 Logging.warn(ex); … … 655 721 if (time == null) { 656 722 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 present723 time = Instant.ofEpochMilli(file.lastModified()); //use lastModified time if no EXIF time present 658 724 } 659 725 setExifTime(time); … … 705 771 } 706 772 707 ifNotNull(dirGps.getGpsDate(), this::setExifGpsTime);773 ifNotNull(dirGps.getGpsDate(), d -> setExifGpsTime(d.toInstant())); 708 774 709 775 IptcDirectory dirIptc = metadata.getFirstDirectoryOfType(IptcDirectory.class); -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r17132 r17715 3 3 4 4 import java.awt.Color; 5 import java.time.Instant; 5 6 import java.util.ArrayList; 6 7 import java.util.Date; … … 16 17 import org.openstreetmap.josm.tools.Logging; 17 18 import org.openstreetmap.josm.tools.Utils; 18 import org.openstreetmap.josm.tools.date.DateUtils;19 19 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; 20 20 … … 66 66 attr = new HashMap<>(0); 67 67 attr.putAll(p.attr); 68 if (p.getDate() != null) {69 attr.put(PT_TIME, p.getDate());70 }71 68 lat = p.lat; 72 69 lon = p.lon; … … 139 136 * @param time the time to set 140 137 * @since 9383 141 */ 138 * @deprecated Use {@link #setInstant(Instant)} 139 */ 140 @Deprecated 142 141 public void setTime(Date time) { 143 set TimeInMillis(time.getTime());142 setInstant(time.toInstant()); 144 143 } 145 144 … … 149 148 * @param ts seconds from the epoch 150 149 * @since 13210 151 */ 150 * @deprecated Use {@link #setInstant(Instant)} 151 */ 152 @Deprecated 152 153 public void setTime(long ts) { 153 set TimeInMillis(ts * 1000);154 setInstant(Instant.ofEpochSecond(ts)); 154 155 } 155 156 … … 161 162 */ 162 163 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); 164 174 } 165 175 … … 185 195 */ 186 196 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(); 189 199 } 190 200 … … 196 206 */ 197 207 public boolean hasDate() { 198 return attr.get(PT_TIME) instanceof Date;208 return attr.get(PT_TIME) instanceof Instant; 199 209 } 200 210 … … 204 214 * @return a copy of the Date object associated with this waypoint 205 215 * @since 14456 206 */ 216 * @deprecated Use {@link #getInstant()} 217 */ 218 @Deprecated 207 219 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() { 217 231 if (attr != null) { 218 232 final Object obj = attr.get(PT_TIME); 219 233 220 if (obj instanceof Date) {221 return ( Date) obj;234 if (obj instanceof Instant) { 235 return (Instant) obj; 222 236 } else if (obj == null) { 223 237 Logging.trace("Waypoint {0} value unset", PT_TIME); -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r17439 r17715 10 10 import java.awt.event.ActionEvent; 11 11 import java.io.File; 12 import java.text.DateFormat; 12 import java.time.Instant; 13 import java.time.format.DateTimeFormatter; 14 import java.time.format.FormatStyle; 15 import java.time.temporal.ChronoUnit; 13 16 import java.util.ArrayList; 14 17 import java.util.Arrays; … … 157 160 */ 158 161 public static String getTimespanForTrack(IGpxTrack trk) { 159 Date[] bounds = GpxData.getMinMaxTimeForTrack(trk);162 Instant[] bounds = GpxData.getMinMaxTimeForTrack(trk); 160 163 return bounds != null ? formatTimespan(bounds) : ""; 161 164 } … … 166 169 * @return The timespan as a string 167 170 */ 168 public static String formatTimespan( Date[] bounds) {171 public static String formatTimespan(Instant[] bounds) { 169 172 String ts = ""; 170 Date Format df = DateUtils.getDateFormat(DateFormat.SHORT);173 DateTimeFormatter df = DateUtils.getDateFormatter(FormatStyle.SHORT); 171 174 String earliestDate = df.format(bounds[0]); 172 175 String latestDate = df.format(bounds[1]); 173 176 174 177 if (earliestDate.equals(latestDate)) { 175 Date Format tf = DateUtils.getTimeFormat(DateFormat.SHORT);178 DateTimeFormatter tf = DateUtils.getTimeFormatter(FormatStyle.SHORT); 176 179 ts += earliestDate + ' '; 177 180 ts += tf.format(bounds[0]) + " - " + tf.format(bounds[1]); 178 181 } else { 179 Date Format dtf = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);182 DateTimeFormatter dtf = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.MEDIUM); 180 183 ts += dtf.format(bounds[0]) + " - " + dtf.format(bounds[1]); 181 184 } 182 185 183 int diff = (int) (bounds[1].getTime() - bounds[0].getTime()) / 1000;186 long diff = ChronoUnit.SECONDS.between(bounds[1], bounds[0]); 184 187 ts += String.format(" (%d:%02d)", diff / 3600, (diff % 3600) / 60); 185 188 return ts; … … 355 358 long to = toDate.getTime(); 356 359 for (IGpxTrack trk : data.getTracks()) { 357 Date[] t = GpxData.getMinMaxTimeForTrack(trk);360 Instant[] t = GpxData.getMinMaxTimeForTrack(trk); 358 361 359 362 if (t == null) continue; 360 long tm = t[1]. getTime();363 long tm = t[1].toEpochMilli(); 361 364 trackVisibility[i] = (tm == 0 && showWithoutDate) || (from <= tm && tm <= to); 362 365 i++; -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r17626 r17715 24 24 import java.io.IOException; 25 25 import java.time.DateTimeException; 26 import java.time.Instant; 26 27 import java.util.ArrayList; 27 28 import java.util.Arrays; … … 878 879 wpt.setTimeInMillis(DateUtils.tsFromString(v)); 879 880 } else if (!n.isTimestampEmpty()) { 880 wpt.set Time(Integer.toUnsignedLong(n.getRawTimestamp()));881 wpt.setInstant(Instant.ofEpochSecond(Integer.toUnsignedLong(n.getRawTimestamp()))); 881 882 } 882 883 } catch (UncheckedParseException | DateTimeException e) { -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r17548 r17715 28 28 import java.text.ParseException; 29 29 import java.text.SimpleDateFormat; 30 import java.time.Instant; 31 import java.time.ZoneOffset; 32 import java.time.format.DateTimeFormatter; 33 import java.time.format.FormatStyle; 30 34 import java.util.ArrayList; 31 35 import java.util.Arrays; 32 36 import java.util.Collections; 33 37 import java.util.Comparator; 34 import java.util.Date;35 38 import java.util.Dictionary; 36 39 import java.util.Hashtable; … … 768 771 void updateExifComponents(ImageEntry img) { 769 772 imgDisp.setImage(img); 770 Date date = img.getExifTime();773 Instant date = img.getExifInstant(); 771 774 if (date != null) { 772 Date Format df = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);773 df.setTimeZone(DateUtils.UTC); // EXIF data does not contain timezone information and is read as UTC775 DateTimeFormatter df = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.MEDIUM) 776 .withZone(ZoneOffset.UTC); // EXIF data does not contain timezone information and is read as UTC 774 777 lbExifTime.setText(df.format(date)); 775 778 tfGpsTime.setText(df.format(date)); … … 1260 1263 1261 1264 // Init variables 1262 long firstExifDate = imgs.get(0).getExif Time().getTime();1265 long firstExifDate = imgs.get(0).getExifInstant().toEpochMilli(); 1263 1266 1264 1267 // Finds first GPX point … … 1334 1337 .filter(e -> e.getExifCoor() == null || exif) 1335 1338 .filter(e -> tagged || !e.isTagged() || e.getExifCoor() != null) 1336 .sorted(Comparator.comparing(ImageEntry::getExif Time))1339 .sorted(Comparator.comparing(ImageEntry::getExifInstant)) 1337 1340 .collect(Collectors.toList()); 1338 1341 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r17188 r17715 13 13 import java.awt.event.KeyEvent; 14 14 import java.awt.event.WindowEvent; 15 import java.text.DateFormat; 16 import java.text.SimpleDateFormat; 15 import java.time.ZoneOffset; 16 import java.time.format.DateTimeFormatter; 17 import java.time.format.FormatStyle; 17 18 import java.util.Collections; 18 19 import java.util.List; … … 472 473 } 473 474 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); 485 479 486 480 if (entry.hasExifTime()) { 487 osd.append(tr("\nEXIF time: {0}", dtf.format(entry.getExif Time())));481 osd.append(tr("\nEXIF time: {0}", dtf.format(entry.getExifInstant()))); 488 482 } 489 483 if (entry.hasGpsTime()) { 490 osd.append(tr("\nGPS time: {0}", dtf.format(entry.getGps Time())));484 osd.append(tr("\nGPS time: {0}", dtf.format(entry.getGpsInstant()))); 491 485 } 492 486 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 13 13 import java.awt.event.MouseEvent; 14 14 import java.awt.event.MouseListener; 15 import java.time.Instant; 15 16 import java.util.Arrays; 16 17 import java.util.Comparator; … … 88 89 String name = (String) Optional.ofNullable(attr.get(GpxConstants.GPX_NAME)).orElse(""); 89 90 String desc = (String) Optional.ofNullable(attr.get(GpxConstants.GPX_DESC)).orElse(""); 90 Date[] time = GpxData.getMinMaxTimeForTrack(trk);91 Instant[] time = GpxData.getMinMaxTimeForTrack(trk); 91 92 String url = (String) Optional.ofNullable(attr.get("url")).orElse(""); 92 93 tracks[i] = new Object[]{name, desc, time, trk.length(), url, trk}; … … 140 141 t.setRowSorter(rowSorter); 141 142 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])); 143 144 rowSorter.setComparator(3, Comparator.comparingDouble(length -> (double) length)); 144 145 // default column widths … … 150 151 public Component getTableCellRendererComponent( 151 152 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)); 154 155 } 155 156 return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertFromGpxLayerAction.java
r17586 r17715 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; 9 import java.time.Instant; 9 10 import java.util.ArrayList; 10 11 import java.util.Date; … … 36 37 import org.openstreetmap.josm.spi.preferences.Config; 37 38 import org.openstreetmap.josm.tools.GBC; 38 import org.openstreetmap.josm.tools.date.DateUtils;39 39 40 40 /** … … 123 123 String key = entry.getKey(); 124 124 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)) { 126 126 keys.add(key); 127 127 } … … 129 129 // only convert when required 130 130 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)) { 132 132 // timestamps should always be converted 133 Date date = (Date) obj;133 Instant date = (Instant) obj; 134 134 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)); 138 138 } 139 139 } -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/DateFilterPanel.java
r16553 r17715 7 7 import java.awt.GridBagLayout; 8 8 import java.awt.event.ActionListener; 9 import java.time.Instant; 9 10 import java.time.ZoneId; 10 11 import java.time.ZonedDateTime; … … 52 53 53 54 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 } 57 63 58 64 dateFrom.setDate(startTime); -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r16913 r17715 22 22 import java.io.BufferedReader; 23 23 import java.io.IOException; 24 import java.time.Instant; 24 25 import java.util.ArrayList; 25 26 import java.util.Arrays; 26 27 import java.util.Collections; 27 import java.util.Date;28 28 import java.util.LinkedList; 29 29 import java.util.List; … … 565 565 double now = System.currentTimeMillis()/1000.0; 566 566 if (colored == ColorMode.TIME) { 567 Date[] bounds = data.getMinMaxTimeForAllTracks();567 Instant[] bounds = data.getMinMaxTimeForAllTracks(); 568 568 if (bounds.length >= 2) { 569 minval = bounds[0].get Time()/1000.0;570 maxval = bounds[1].get Time()/1000.0;569 minval = bounds[0].getEpochSecond(); 570 maxval = bounds[1].getEpochSecond(); 571 571 } else { 572 572 minval = 0; -
trunk/src/org/openstreetmap/josm/io/nmea/NmeaReader.java
r16643 r17715 366 366 // As this sentence has no complete time only use it 367 367 // if there is no time so far 368 currentwp.set Time(d);368 currentwp.setInstant(d.toInstant()); 369 369 } 370 370 // elevation … … 494 494 } 495 495 // time: this sentence has complete time so always use it. 496 currentwp.set Time(d);496 currentwp.setInstant(d.toInstant()); 497 497 // speed 498 498 accu = e[RMC.SPEED.position]; … … 544 544 if (ps.pWp != currentwp) { 545 545 if (ps.pWp != null) { 546 ps.pWp.get Date();546 ps.pWp.getInstant(); 547 547 } 548 548 ps.pWp = currentwp; -
trunk/src/org/openstreetmap/josm/io/rtklib/RtkLibPosReader.java
r16643 r17715 91 91 Double.parseDouble(fields[IDX_LON]))); 92 92 currentwp.put(GpxConstants.PT_ELE, fields[IDX_HEIGHT]); 93 currentwp.set Time(parseDate(fields[IDX_DATE]+" "+fields[IDX_TIME]));93 currentwp.setInstant(parseDate(fields[IDX_DATE]+" "+fields[IDX_TIME]).toInstant()); 94 94 currentwp.put(GpxConstants.RTKLIB_Q, Integer.parseInt(fields[IDX_Q])); 95 95 currentwp.put(GpxConstants.PT_SAT, fields[IDX_NS]); -
trunk/src/org/openstreetmap/josm/io/session/GeoImageSessionExporter.java
r14741 r17715 87 87 } 88 88 if (entry.hasGpsTime()) { 89 addAttr("gps-time", Long.toString(entry.getGps Time().getTime()), imgElem, support);89 addAttr("gps-time", Long.toString(entry.getGpsInstant().toEpochMilli()), imgElem, support); 90 90 } 91 91 if (entry.getExifOrientation() != null) { … … 93 93 } 94 94 if (entry.hasExifTime()) { 95 addAttr("exif-time", Long.toString(entry.getExif Time().getTime()), imgElem, support);95 addAttr("exif-time", Long.toString(entry.getExifInstant().toEpochMilli()), imgElem, support); 96 96 } 97 97 if (entry.hasExifGpsTime()) { 98 addAttr("exif-gps-time", Long.toString(entry.getExifGps Time().getTime()), imgElem, support);98 addAttr("exif-gps-time", Long.toString(entry.getExifGpsInstant().toEpochMilli()), imgElem, support); 99 99 } 100 100 if (entry.getExifCoor() != null) { -
trunk/src/org/openstreetmap/josm/io/session/GeoImageSessionImporter.java
r14205 r17715 6 6 import java.io.File; 7 7 import java.io.IOException; 8 import java.time.Instant; 8 9 import java.util.ArrayList; 9 import java.util.Date;10 10 import java.util.List; 11 11 … … 90 90 break; 91 91 case "gps-time": 92 entry.setGpsTime( new Date(Long.parseLong(attrElem.getTextContent())));92 entry.setGpsTime(Instant.ofEpochMilli(Long.parseLong(attrElem.getTextContent()))); 93 93 break; 94 94 case "exif-orientation": … … 96 96 break; 97 97 case "exif-time": 98 entry.setExifTime( new Date(Long.parseLong(attrElem.getTextContent())));98 entry.setExifTime(Instant.ofEpochMilli(Long.parseLong(attrElem.getTextContent()))); 99 99 break; 100 100 case "exif-gps-time": 101 entry.setExifGpsTime( new Date(Long.parseLong(attrElem.getTextContent())));101 entry.setExifGpsTime(Instant.ofEpochMilli(Long.parseLong(attrElem.getTextContent()))); 102 102 break; 103 103 case "exif-coordinates": -
trunk/src/org/openstreetmap/josm/tools/ExifReader.java
r17548 r17715 6 6 import java.io.IOException; 7 7 import java.time.DateTimeException; 8 import java.time.Instant; 8 9 import java.util.Date; 9 10 import java.util.List; … … 42 43 * @param filename The JPEG file to read 43 44 * @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 45 48 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); 49 62 } catch (JpegProcessingException | IOException e) { 50 63 Logging.error(e); … … 58 71 * @return The date/time read in the EXIF section, or {@code null} if not found 59 72 * @since 11745 60 */ 73 * @deprecated Use {@link #readInstant(Metadata)} 74 */ 75 @Deprecated 61 76 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) { 62 87 try { 63 88 String dateTimeOrig = null; … … 109 134 if (dateStr != null) { 110 135 dateStr = dateStr.replace('/', ':'); // workaround for HTC Sensation bug, see #7228 111 final Date date = DateUtils.fromString(dateStr);136 Instant date = DateUtils.parseInstant(dateStr); 112 137 if (subSeconds != null) { 113 138 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))); 115 140 } catch (NumberFormatException e) { 116 141 Logging.warn("Failed parsing sub seconds from [{0}]", subSeconds); -
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r17712 r17715 287 287 * @return the date format used for GPX waypoints 288 288 * @since 14055 289 */ 289 * @deprecated Use {@link Instant#toString()} 290 */ 291 @Deprecated 290 292 public static DateFormat getGpxFormat() { 291 293 SimpleDateFormat result = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); -
trunk/test/unit/org/openstreetmap/josm/data/ImageDataTest.java
r17310 r17715 8 8 9 9 import java.io.File; 10 import java.time.Instant; 10 11 import java.util.ArrayList; 11 12 import java.util.Arrays; 12 13 import java.util.Collections; 13 import java.util.Date;14 14 import java.util.List; 15 15 … … 28 28 class ImageDataTest { 29 29 30 private static ImageEntry newImageEntry(String file, DateexifTime) {30 private static ImageEntry newImageEntry(String file, Instant exifTime) { 31 31 ImageEntry entry = new ImageEntry(new File(file)); 32 32 entry.setExifTime(exifTime); … … 65 65 @Test 66 66 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)); 69 69 70 70 ArrayList<ImageEntry> list = new ArrayList<>(); -
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java
r17275 r17715 10 10 11 11 import java.io.IOException; 12 import java.time.Instant; 12 13 import java.util.ArrayList; 13 14 import java.util.Arrays; … … 337 338 WayPoint p4 = new WayPoint(LatLon.NORTH_POLE); 338 339 WayPoint p5 = new WayPoint(LatLon.NORTH_POLE); 339 p1.set Time(new Date(200020));340 p2.set Time(new Date(100020));341 p4.set Time(new Date(500020));340 p1.setInstant(new Date(200020).toInstant()); 341 p2.setInstant(new Date(100020).toInstant()); 342 p4.setInstant(new Date(500020).toInstant()); 342 343 data.addTrack(new GpxTrack(Arrays.asList(Arrays.asList(p1, p2)), Collections.emptyMap())); 343 344 data.addTrack(new GpxTrack(Arrays.asList(Arrays.asList(p3, p4, p5)), Collections.emptyMap())); 344 345 345 Date[] times = data.getMinMaxTimeForAllTracks();346 Instant[] times = data.getMinMaxTimeForAllTracks(); 346 347 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]); 349 350 } 350 351 -
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxImageCorrelationTest.java
r17275 r17715 58 58 59 59 final GpxImageEntry ib = new GpxImageEntry(); 60 ib.setExifTime(DateUtils. fromString("2016:01:03 11:54:58")); // 5 minutes before start of GPX60 ib.setExifTime(DateUtils.parseInstant("2016:01:03 11:54:58")); // 5 minutes before start of GPX 61 61 ib.createTmp(); 62 62 final GpxImageEntry i0 = new GpxImageEntry(); 63 i0.setExifTime(DateUtils. fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX63 i0.setExifTime(DateUtils.parseInstant("2016:01:03 11:59:54")); // 4 sec before start of GPX 64 64 i0.createTmp(); 65 65 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")); 67 67 i1.createTmp(); 68 68 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")); 70 70 i2.createTmp(); 71 71 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")); 73 73 i3.createTmp(); 74 74 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")); 76 76 i4.createTmp(); 77 77 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")); 79 79 i5.createTmp(); 80 80 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")); 82 82 i6.createTmp(); 83 83 … … 119 119 assertEquals(null, i6.getElevation()); 120 120 121 assertEquals(null, ib.getGps Time());122 assertEquals(DateUtils. fromString("2016:01:03 11:59:54"), i0.getGpsTime()); // original time is kept123 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()); 126 126 127 127 clearTmp(images); -
trunk/test/unit/org/openstreetmap/josm/data/gpx/WayPointTest.java
r17275 r17715 5 5 import org.junit.jupiter.api.Test; 6 6 import org.openstreetmap.josm.TestUtils; 7 import org.openstreetmap.josm.data.coor.LatLon; 7 8 import org.openstreetmap.josm.testutils.JOSMTestRules; 8 9 … … 10 11 import nl.jqno.equalsverifier.EqualsVerifier; 11 12 import nl.jqno.equalsverifier.Warning; 13 14 import java.time.Instant; 15 16 import static org.junit.jupiter.api.Assertions.assertEquals; 17 import static org.junit.jupiter.api.Assertions.assertNotEquals; 12 18 13 19 /** … … 37 43 .verify(); 38 44 } 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 } 39 60 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java
r17275 r17715 10 10 import java.io.File; 11 11 import java.nio.charset.StandardCharsets; 12 import java.text.DateFormat;13 12 import java.util.Collection; 14 13 import java.util.Collections; … … 39 38 import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker; 40 39 import org.openstreetmap.josm.tools.Logging; 41 import org.openstreetmap.josm.tools.date.DateUtils;42 40 43 41 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 245 243 assertEquals(3, trackpoints.size()); 246 244 Iterator<WayPoint> it = trackpoints.iterator(); 247 DateFormat gpxFormat = DateUtils.getGpxFormat();248 245 WayPoint p1 = it.next(); 249 246 assertEquals(new LatLon(47.0, 9.0), p1.getCoor()); 250 247 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))); 252 249 WayPoint p2 = it.next(); 253 250 assertEquals(new LatLon(47.1, 9.1), p2.getCoor()); 254 251 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))); 256 253 WayPoint p3 = it.next(); 257 254 assertEquals(new LatLon(47.05, 9.05), p3.getCoor()); 258 255 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))); 260 257 } 261 258 -
trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImagesTest.java
r17275 r17715 48 48 final GpxData gpx = GpxReaderTest.parseGpxData("nodist/data/2094047.gpx"); 49 49 final ImageEntry i0 = new ImageEntry(); 50 i0.setExifTime(DateUtils. fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX50 i0.setExifTime(DateUtils.parseInstant("2016:01:03 11:59:54")); // 4 sec before start of GPX 51 51 i0.createTmp(); 52 52 assertEquals(Pair.create(GpxTimezone.ZERO, GpxTimeOffset.seconds(-4)), -
trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/ImageEntryTest.java
r17580 r17715 27 27 ImageEntry e = new ImageEntry(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))); 28 28 e.extractExif(); 29 assertNotNull(e.getExif Time());29 assertNotNull(e.getExifInstant()); 30 30 } 31 31 -
trunk/test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java
r17275 r17715 11 11 import java.nio.file.Files; 12 12 import java.nio.file.Paths; 13 import java.t ext.SimpleDateFormat;13 import java.time.Instant; 14 14 import java.util.ArrayList; 15 import java.util.Date;16 15 import java.util.List; 17 16 import java.util.TimeZone; 18 17 19 import org.junit.jupiter.api.BeforeEach;20 18 import org.junit.jupiter.api.Test; 21 19 import org.junit.jupiter.api.extension.RegisterExtension; … … 45 43 public JOSMTestRules test = new JOSMTestRules(); 46 44 47 private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");48 49 /**50 * Forces the timezone.51 */52 @BeforeEach53 public void setUp() {54 iso8601.setTimeZone(DateUtils.UTC);55 }56 57 45 /** 58 46 * Tests reading a nmea file. … … 68 56 69 57 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).get Date(), 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)); 74 62 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()); 78 66 79 67 assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor()); … … 171 159 } 172 160 173 private static DatereadDate(String nmeaLine) throws IOException, SAXException {174 return readWayPoint(nmeaLine).get Date();161 private static Instant readDate(String nmeaLine) throws IOException, SAXException { 162 return readWayPoint(nmeaLine).getInstant(); 175 163 } 176 164 … … 185 173 @Test 186 174 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")); 193 181 } 194 182 -
trunk/test/unit/org/openstreetmap/josm/io/rtklib/RtkLibPosReaderTest.java
r17275 r17715 7 7 import java.nio.file.Files; 8 8 import java.nio.file.Paths; 9 import java.t ext.SimpleDateFormat;9 import java.time.Instant; 10 10 import java.util.ArrayList; 11 11 import java.util.List; 12 12 import java.util.TimeZone; 13 13 14 import org.junit.jupiter.api.BeforeEach;15 14 import org.junit.jupiter.api.Test; 16 15 import org.junit.jupiter.api.extension.RegisterExtension; … … 35 34 public JOSMTestRules test = new JOSMTestRules(); 36 35 37 private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");38 39 /**40 * Forces the timezone.41 */42 @BeforeEach43 public void setUp() {44 iso8601.setTimeZone(DateUtils.UTC);45 }46 47 36 private static RtkLibPosReader read(String path) throws IOException, SAXException { 48 37 TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin")); … … 62 51 63 52 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).get Date(), 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)); 68 57 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()); 72 61 73 62 assertEquals(new LatLon(46.948881673, -1.484757046), wayPoints.get(0).getCoor()); -
trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java
r17275 r17715 8 8 import java.io.IOException; 9 9 import java.text.DecimalFormat; 10 import java.text.ParseException; 11 import java.text.SimpleDateFormat; 12 import java.util.Date; 10 import java.time.Instant; 13 11 14 12 import org.junit.jupiter.api.BeforeEach; … … 48 46 /** 49 47 * Test time extraction 50 * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file51 48 */ 52 49 @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); 56 53 } 57 54 58 55 /** 59 56 * Tests reading sub-seconds from the EXIF header 60 * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file61 57 */ 62 58 @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); 70 62 } 71 63 72 64 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); 74 67 } 75 68 … … 125 118 @Test 126 119 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"); 128 121 } 129 122 … … 134 127 @Test 135 128 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"); 138 131 } 139 132 }
Note:
See TracChangeset
for help on using the changeset viewer.