Ticket #16995: josm-ticket-16995-corrupt-timestamps-when-using-ExportRelationToGpxAction-fix__without-y2038-fix.patch
File josm-ticket-16995-corrupt-timestamps-when-using-ExportRelationToGpxAction-fix__without-y2038-fix.patch, 8.7 KB (added by , 6 years ago) |
---|
-
src/org/openstreetmap/josm/actions/relation/ExportRelationToGpxAction.java
20 20 import java.util.Map; 21 21 import java.util.Set; 22 22 import java.util.Stack; 23 import java.util.concurrent.TimeUnit; 23 24 24 25 import org.openstreetmap.josm.actions.GpxExportAction; 25 26 import org.openstreetmap.josm.actions.IPrimitiveAction; … … 173 174 174 175 GpxData gpxData = new GpxData(); 175 176 String layerName = " (GPX export)"; 176 long time = System.currentTimeMillis()-24*3600*1000;177 long time = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) - 24*3600; 177 178 178 179 if (!flat.isEmpty()) { 179 180 Map<String, Object> trkAttr = new HashMap<>(); … … 196 197 if (trkAttr.isEmpty()) { 197 198 Relation r = Way.getParentRelations(Arrays.asList(flat.get(i).getWay())) 198 199 .stream().filter(relsFound::contains).findFirst().orElseGet(null); 199 if (r != null) 200 if (r != null) { 200 201 trkAttr.put("name", r.getName() != null ? r.getName() : r.getId()); 202 trkAttr.put("desc", tr("based on osm route relation data, timestamps are synthetic")); 203 } 201 204 GpxData.ensureUniqueName(trkAttr, names); 202 205 } 203 206 List<Node> ln = flat.get(i).getWay().getNodes(); 204 207 if (wct.get(i).direction == WayConnectionType.Direction.BACKWARD) 205 208 Collections.reverse(ln); 206 209 for (Node n: ln) { 207 trkseg.add(OsmDataLayer.nodeToWayPoint(n, time));208 time += 1 000;210 trkseg.add(OsmDataLayer.nodeToWayPoint(n, TimeUnit.SECONDS.toMillis(time))); 211 time += 1; 209 212 } 210 213 } 211 214 } -
src/org/openstreetmap/josm/data/gpx/WayPoint.java
128 128 } 129 129 130 130 /** 131 * Sets the {@link #time} field as well as the {@link #PT_TIME} attribute to the specified time 131 * Sets the {@link #time} field as well as the {@link #PT_TIME} attribute to the specified time. 132 132 * 133 133 * @param time the time to set 134 134 * @since 9383 … … 139 139 } 140 140 141 141 /** 142 * Convert the time stamp of the waypoint into seconds from the epoch 142 * Sets the {@link #time} field as well as the {@link #PT_TIME} attribute to the specified time. 143 * 144 * @param ts seconds from the epoch 145 * @since 13210 143 146 */ 144 public void setTime() { 145 setTimeFromAttribute(); 147 public void setTime(long ts) { 148 this.time = ts; 149 this.attr.put(PT_TIME, DateUtils.fromTimestamp(ts)); 146 150 } 147 151 148 152 /** 149 * Set the the time stamp of the waypoint into seconds from the epoch, 150 * @param time millisecond from the epoch 151 * @since 13210 153 * Sets the {@link #time} field as well as the {@link #PT_TIME} attribute to the specified time. 154 * 155 * @param ts milliseconds from the epoch 156 * @since xxx 152 157 */ 153 public void setTime(long time) { 154 this.time = time / 1000.; 158 public void setTimeInMillis(long ts) { 159 this.time = ts / 1000.; 160 this.attr.put(PT_TIME, DateUtils.fromTimestampInMillis(ts)); 161 } 162 163 /** 164 * Convert the time stamp of the waypoint into seconds from the epoch. 165 * 166 * @deprecated call {@link #setTimeFromAttribute()} directly if you need this 167 */ 168 @Deprecated 169 public void setTime() { 170 setTimeFromAttribute(); 155 171 } 156 172 157 173 /** -
src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
192 192 */ 193 193 protected int changesetId; 194 194 195 /** 196 * A time value, measured in seconds from the epoch, or in other words, 197 * a number of seconds that have passed since 1970-01-01T00:00:00Z 198 */ 195 199 protected int timestamp; 196 200 197 201 /** -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
779 779 * @since 13210 780 780 */ 781 781 public static WayPoint nodeToWayPoint(Node n) { 782 return nodeToWayPoint(n, 0);782 return nodeToWayPoint(n, Long.MIN_VALUE); 783 783 } 784 784 785 785 /** 786 786 * @param n the {@code Node} to convert 787 * @param t ime a time value in milliseconds from the epoch.787 * @param ts a timestamp value, in milliseconds from the epoch 788 788 * @return {@code WayPoint} object 789 789 * @since 13210 790 790 */ 791 public static WayPoint nodeToWayPoint(Node n, long t ime) {791 public static WayPoint nodeToWayPoint(Node n, long ts) { 792 792 WayPoint wpt = new WayPoint(n.getCoor()); 793 793 794 794 // Position info 795 795 796 796 addDoubleIfPresent(wpt, n, GpxConstants.PT_ELE); 797 797 798 if (time > 0) { 799 wpt.put(GpxConstants.PT_TIME, DateUtils.fromTimestamp(time)); 800 wpt.setTime(time); 798 if (ts != Long.MIN_VALUE) { 799 wpt.setTimeInMillis(ts); 801 800 } else if (n.hasKey(GpxConstants.PT_TIME)) { 802 wpt.put(GpxConstants.PT_TIME, DateUtils.fromString(n.get(GpxConstants.PT_TIME))); 803 wpt.setTime(); 801 wpt.setTime(DateUtils.fromString(n.get(GpxConstants.PT_TIME))); 804 802 } else if (!n.isTimestampEmpty()) { 805 wpt.put(GpxConstants.PT_TIME, DateUtils.fromTimestamp(n.getRawTimestamp())); 806 wpt.setTime(); 803 wpt.setTime(n.getRawTimestamp()); 807 804 } 808 805 809 806 addDoubleIfPresent(wpt, n, GpxConstants.PT_MAGVAR); -
src/org/openstreetmap/josm/io/GpxReader.java
444 444 case "cmt": 445 445 case "desc": 446 446 currentWayPoint.put(localName, accumulator.toString()); 447 currentWayPoint.setTime ();447 currentWayPoint.setTimeFromAttribute(); 448 448 break; 449 449 case "rtept": 450 450 currentState = states.pop(); -
src/org/openstreetmap/josm/io/nmea/NmeaReader.java
524 524 ps.pDate = currentDate; 525 525 if (ps.pWp != currentwp) { 526 526 if (ps.pWp != null) { 527 ps.pWp.setTime ();527 ps.pWp.setTimeFromAttribute(); 528 528 } 529 529 ps.pWp = currentwp; 530 530 ps.waypoints.add(currentwp); -
src/org/openstreetmap/josm/tools/date/DateUtils.java
152 152 * @return The formatted date 153 153 * @since 14055 154 154 */ 155 public static synchronized String fromTimestamp(long timestamp) { 156 final ZonedDateTime temporal = Instant.ofEpochMilli(TimeUnit.SECONDS.toMillis(timestamp)).atZone(ZoneOffset.UTC); 155 public static String fromTimestamp(long timestamp) { 156 return fromTimestampInMillis(TimeUnit.SECONDS.toMillis(timestamp)); 157 } 158 159 /** 160 * Formats a date to the XML UTC format regardless of current locale. 161 * @param timestamp number of milliseconds since the epoch 162 * @return The formatted date 163 * @since xxx 164 */ 165 public static synchronized String fromTimestampInMillis(long timestamp) { 166 final ZonedDateTime temporal = Instant.ofEpochMilli(timestamp).atZone(ZoneOffset.UTC); 157 167 return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(temporal); 158 168 } 159 169