Changeset 14055 in josm


Ignore:
Timestamp:
2018-07-28T01:03:54+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #14103 - GPX → OSM: convert additional tags

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r13210 r14055  
    162162        if (attr.containsKey(PT_TIME)) {
    163163            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());
    165166                this.time = time.getTime() / 1000.;
    166167                return time;
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r14037 r14055  
    773773
    774774        if (time > 0) {
     775            wpt.put(GpxConstants.PT_TIME, DateUtils.fromTimestamp(time));
    775776            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();
    776780        } else if (!n.isTimestampEmpty()) {
    777             wpt.put("time", DateUtils.fromTimestamp(n.getRawTimestamp()));
     781            wpt.put(GpxConstants.PT_TIME, DateUtils.fromTimestamp(n.getRawTimestamp()));
    778782            wpt.setTime();
    779783        }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java

    r14051 r14055  
    88import java.awt.event.ActionEvent;
    99import java.io.File;
     10import java.text.DateFormat;
    1011import java.util.ArrayList;
    1112import java.util.Arrays;
    1213import java.util.Collection;
     14import java.util.Date;
    1315import java.util.Iterator;
    1416import java.util.List;
     17import java.util.Map.Entry;
    1518import java.util.Optional;
    1619
     
    6770    public static class FromGpxLayer extends ConvertToDataLayerAction<GpxLayer> {
    6871
     72        private final DateFormat timeFormatter = DateUtils.getGpxFormat();
     73
    6974        /**
    7075         * Creates a new {@code FromGpxLayer}.
     
    8388                    for (WayPoint p : segment.getWayPoints()) {
    8489                        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                                }
    91109                            }
    92                         }
    93                         String elestr = p.getString(GpxConstants.PT_ELE);
    94                         if (elestr != null) {
    95                             n.put("ele", elestr);
    96110                        }
    97111                        ds.addPrimitive(n);
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r13192 r14055  
    1111import java.io.File;
    1212import java.text.DateFormat;
    13 import java.text.SimpleDateFormat;
    1413import java.util.ArrayList;
    1514import java.util.Collection;
     
    3534import org.openstreetmap.josm.tools.ImageProvider;
    3635import org.openstreetmap.josm.tools.Logging;
     36import org.openstreetmap.josm.tools.date.DateUtils;
    3737import org.openstreetmap.josm.tools.template_engine.ParseError;
    3838import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
     
    209209    public static final String LABEL_PATTERN_DESC = "{desc}";
    210210
    211     private final DateFormat timeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
     211    private final DateFormat timeFormatter = DateUtils.getGpxFormat();
    212212    private final TemplateEngineDataProvider dataProvider;
    213213    private final String text;
     
    262262    public WayPoint convertToWayPoint() {
    263263        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))));
    265265        if (text != null) {
    266266            wpt.addExtension("text", text);
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r12620 r14055  
    148148     * @param timestamp number of seconds since the epoch
    149149     * @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) {
    152153        final ZonedDateTime temporal = Instant.ofEpochMilli(TimeUnit.SECONDS.toMillis(timestamp)).atZone(ZoneOffset.UTC);
    153154        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);
    154164    }
    155165
     
    248258
    249259    /**
     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    /**
    250269     * Formats a date to be displayed to current user, based on user preferences.
    251270     * @param date The date to display. Must not be {@code null}
Note: See TracChangeset for help on using the changeset viewer.