Changeset 14055 in josm
- Timestamp:
- 2018-07-28T01:03:54+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r13210 r14055 162 162 if (attr.containsKey(PT_TIME)) { 163 163 try { 164 final Date time = DateUtils.fromString(get(PT_TIME).toString()); 164 final Object obj = get(PT_TIME); 165 final Date time = obj instanceof Date ? (Date) obj : DateUtils.fromString(obj.toString()); 165 166 this.time = time.getTime() / 1000.; 166 167 return time; -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r14037 r14055 773 773 774 774 if (time > 0) { 775 wpt.put(GpxConstants.PT_TIME, DateUtils.fromTimestamp(time)); 775 776 wpt.setTime(time); 777 } else if (n.hasKey(GpxConstants.PT_TIME)) { 778 wpt.put(GpxConstants.PT_TIME, DateUtils.fromString(n.get(GpxConstants.PT_TIME))); 779 wpt.setTime(); 776 780 } else if (!n.isTimestampEmpty()) { 777 wpt.put( "time", DateUtils.fromTimestamp(n.getRawTimestamp()));781 wpt.put(GpxConstants.PT_TIME, DateUtils.fromTimestamp(n.getRawTimestamp())); 778 782 wpt.setTime(); 779 783 } -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java
r14051 r14055 8 8 import java.awt.event.ActionEvent; 9 9 import java.io.File; 10 import java.text.DateFormat; 10 11 import java.util.ArrayList; 11 12 import java.util.Arrays; 12 13 import java.util.Collection; 14 import java.util.Date; 13 15 import java.util.Iterator; 14 16 import java.util.List; 17 import java.util.Map.Entry; 15 18 import java.util.Optional; 16 19 … … 67 70 public static class FromGpxLayer extends ConvertToDataLayerAction<GpxLayer> { 68 71 72 private final DateFormat timeFormatter = DateUtils.getGpxFormat(); 73 69 74 /** 70 75 * Creates a new {@code FromGpxLayer}. … … 83 88 for (WayPoint p : segment.getWayPoints()) { 84 89 Node n = new Node(p.getCoor()); 85 String timestr = p.getString(GpxConstants.PT_TIME); 86 if (timestr != null) { 87 try { 88 n.setTimestamp(DateUtils.fromString(timestr)); 89 } catch (UncheckedParseException e) { 90 Logging.log(Logging.LEVEL_WARN, e); 90 for (Entry<String, Object> entry : p.attr.entrySet()) { 91 String key = entry.getKey(); 92 String str = p.getString(key); 93 if (str != null) { 94 n.put(key, str); 95 if (GpxConstants.PT_TIME.equals(key)) { 96 try { 97 n.setTimestamp(DateUtils.fromString(str)); 98 } catch (UncheckedParseException e) { 99 Logging.log(Logging.LEVEL_WARN, e); 100 } 101 } 102 } else { 103 Object obj = p.get(key); 104 if (obj instanceof Date && GpxConstants.PT_TIME.equals(key)) { 105 Date date = (Date) obj; 106 n.put(key, timeFormatter.format(date)); 107 n.setTimestamp(date); 108 } 91 109 } 92 }93 String elestr = p.getString(GpxConstants.PT_ELE);94 if (elestr != null) {95 n.put("ele", elestr);96 110 } 97 111 ds.addPrimitive(n); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r13192 r14055 11 11 import java.io.File; 12 12 import java.text.DateFormat; 13 import java.text.SimpleDateFormat;14 13 import java.util.ArrayList; 15 14 import java.util.Collection; … … 35 34 import org.openstreetmap.josm.tools.ImageProvider; 36 35 import org.openstreetmap.josm.tools.Logging; 36 import org.openstreetmap.josm.tools.date.DateUtils; 37 37 import org.openstreetmap.josm.tools.template_engine.ParseError; 38 38 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; … … 209 209 public static final String LABEL_PATTERN_DESC = "{desc}"; 210 210 211 private final DateFormat timeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");211 private final DateFormat timeFormatter = DateUtils.getGpxFormat(); 212 212 private final TemplateEngineDataProvider dataProvider; 213 213 private final String text; … … 262 262 public WayPoint convertToWayPoint() { 263 263 WayPoint wpt = new WayPoint(getCoor()); 264 wpt.put( "time", timeFormatter.format(new Date(Math.round(time * 1000))));264 wpt.put(GpxConstants.PT_TIME, timeFormatter.format(new Date(Math.round(time * 1000)))); 265 265 if (text != null) { 266 266 wpt.addExtension("text", text); -
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r12620 r14055 148 148 * @param timestamp number of seconds since the epoch 149 149 * @return The formatted date 150 */ 151 public static synchronized String fromTimestamp(int timestamp) { 150 * @since 14055 151 */ 152 public static synchronized String fromTimestamp(long timestamp) { 152 153 final ZonedDateTime temporal = Instant.ofEpochMilli(TimeUnit.SECONDS.toMillis(timestamp)).atZone(ZoneOffset.UTC); 153 154 return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(temporal); 155 } 156 157 /** 158 * Formats a date to the XML UTC format regardless of current locale. 159 * @param timestamp number of seconds since the epoch 160 * @return The formatted date 161 */ 162 public static synchronized String fromTimestamp(int timestamp) { 163 return fromTimestamp((long) timestamp); 154 164 } 155 165 … … 248 258 249 259 /** 260 * Returns the date format used for GPX waypoints. 261 * @return the date format used for GPX waypoints 262 * @since 14055 263 */ 264 public static DateFormat getGpxFormat() { 265 return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 266 } 267 268 /** 250 269 * Formats a date to be displayed to current user, based on user preferences. 251 270 * @param date The date to display. Must not be {@code null}
Note:
See TracChangeset
for help on using the changeset viewer.