Changeset 14434 in josm
- Timestamp:
- 2018-11-20T01:13:10+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/relation/ExportRelationToGpxAction.java
r14397 r14434 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; … … 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()) { … … 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 } … … 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 } -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r14159 r14434 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 … … 140 140 141 141 /** 142 * Convert the time stamp of the waypoint into seconds from the epoch 143 */ 142 * Convert the time stamp of the waypoint into seconds from the epoch. 143 * 144 * @deprecated call {@link #setTimeFromAttribute()} directly if you need this 145 */ 146 @Deprecated 144 147 public void setTime() { 145 148 setTimeFromAttribute(); … … 147 150 148 151 /** 149 * Set the the time stamp of the waypoint into seconds from the epoch, 150 * @param time millisecond from the epoch 152 * Sets the {@link #time} field as well as the {@link #PT_TIME} attribute to the specified time. 153 * 154 * @param ts seconds from the epoch 151 155 * @since 13210 152 156 */ 153 public void setTime(long time) { 154 this.time = time / 1000.; 157 public void setTime(long ts) { 158 this.time = ts; 159 this.attr.put(PT_TIME, DateUtils.fromTimestamp(ts)); 160 } 161 162 /** 163 * Sets the {@link #time} field as well as the {@link #PT_TIME} attribute to the specified time. 164 * 165 * @param ts milliseconds from the epoch 166 * @since 14434 167 */ 168 public void setTimeInMillis(long ts) { 169 this.time = ts / 1000.; 170 this.attr.put(PT_TIME, DateUtils.fromTimestampInMillis(ts)); 155 171 } 156 172 -
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r13913 r14434 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 … … 327 331 @Override 328 332 public Date getTimestamp() { 329 return new Date(TimeUnit.SECONDS.toMillis( timestamp));333 return new Date(TimeUnit.SECONDS.toMillis(Integer.toUnsignedLong(timestamp))); 330 334 } 331 335 -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r14430 r14434 781 781 */ 782 782 public static WayPoint nodeToWayPoint(Node n) { 783 return nodeToWayPoint(n, 0);783 return nodeToWayPoint(n, Long.MIN_VALUE); 784 784 } 785 785 786 786 /** 787 787 * @param n the {@code Node} to convert 788 * @param time a time value in milliseconds from the epoch.788 * @param time a timestamp value in milliseconds from the epoch. 789 789 * @return {@code WayPoint} object 790 790 * @since 13210 … … 798 798 799 799 try { 800 if (time > 0) { 801 wpt.put(GpxConstants.PT_TIME, DateUtils.fromTimestamp(time)); 802 wpt.setTime(time); 800 if (time > Long.MIN_VALUE) { 801 wpt.setTimeInMillis(time); 803 802 } else if (n.hasKey(GpxConstants.PT_TIME)) { 804 wpt.put(GpxConstants.PT_TIME, DateUtils.fromString(n.get(GpxConstants.PT_TIME))); 805 wpt.setTime(); 803 wpt.setTime(DateUtils.fromString(n.get(GpxConstants.PT_TIME))); 806 804 } else if (!n.isTimestampEmpty()) { 807 wpt.put(GpxConstants.PT_TIME, DateUtils.fromTimestamp(n.getRawTimestamp())); 808 wpt.setTime(); 805 wpt.setTime(Integer.toUnsignedLong(n.getRawTimestamp())); 809 806 } 810 807 } catch (UncheckedParseException e) { -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r14010 r14434 445 445 case "desc": 446 446 currentWayPoint.put(localName, accumulator.toString()); 447 currentWayPoint.setTime ();447 currentWayPoint.setTimeFromAttribute(); 448 448 break; 449 449 case "rtept": -
trunk/src/org/openstreetmap/josm/io/nmea/NmeaReader.java
r14083 r14434 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; -
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r14159 r14434 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 14434 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 } … … 164 174 */ 165 175 public static synchronized String fromTimestamp(int timestamp) { 166 return fromTimestamp( (long) timestamp);176 return fromTimestamp(Integer.toUnsignedLong(timestamp)); 167 177 } 168 178
Note:
See TracChangeset
for help on using the changeset viewer.