Changeset 17839 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2021-05-01T12:37:41+02:00 (3 years ago)
Author:
simon04
Message:

see #14176 - RtkLibPosReader: parse timestamps using DateUtils

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/rtklib/RtkLibPosReader.java

    r17787 r17839  
    77import java.io.InputStreamReader;
    88import java.nio.charset.StandardCharsets;
    9 import java.text.ParseException;
    10 import java.text.SimpleDateFormat;
    119import java.util.ArrayList;
    1210import java.util.Collection;
    1311import java.util.Collections;
    14 import java.util.Date;
    15 import java.util.Locale;
    1612import java.util.Objects;
    1713
     
    5046    private static final int IDX_RATIO = 14;
    5147
    52     private final SimpleDateFormat dateTimeFmtS = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ENGLISH); // 2019/06/08 08:23:15
    53     private final SimpleDateFormat dateTimeFmtL = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS", Locale.ENGLISH); // 2019/06/08 08:23:15.000
    54 
    5548    private final InputStream source;
    5649    private GpxData data;
     
    6457    public RtkLibPosReader(InputStream source) throws IOException {
    6558        this.source = Objects.requireNonNull(source);
    66         dateTimeFmtS.setTimeZone(DateUtils.UTC);
    67         dateTimeFmtL.setTimeZone(DateUtils.UTC);
    68     }
    69 
    70     private Date parseDate(String date) throws ParseException {
    71         return (date.length() > 20 ? dateTimeFmtL : dateTimeFmtS).parse(date);
    7259    }
    7360
     
    9178                                    Double.parseDouble(fields[IDX_LON])));
    9279                            currentwp.put(GpxConstants.PT_ELE, fields[IDX_HEIGHT]);
    93                             currentwp.setInstant(parseDate(fields[IDX_DATE]+" "+fields[IDX_TIME]).toInstant());
     80                            currentwp.setInstant(DateUtils.parseInstant(fields[IDX_DATE]+" "+fields[IDX_TIME]));
    9481                            currentwp.put(GpxConstants.RTKLIB_Q, Integer.parseInt(fields[IDX_Q]));
    9582                            currentwp.put(GpxConstants.PT_SAT, fields[IDX_NS]);
     
    10794                            waypoints.add(currentwp);
    10895                            success++;
    109                         } catch (ParseException | IllegalArgumentException e) {
     96                        } catch (IllegalArgumentException e) {
    11097                            Logging.error(e);
    11198                        }
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r17715 r17839  
    9191                checkLayout(str, "xxxx-xx-xxTxx:xx:xx") ||
    9292                checkLayout(str, "xxxx:xx:xx xx:xx:xx") ||
     93                checkLayout(str, "xxxx/xx/xx xx:xx:xx") ||
    9394                checkLayout(str, "xxxx-xx-xx xx:xx:xxZ") ||
    9495                checkLayout(str, "xxxx-xx-xx xx:xx:xx UTC") ||
     
    115116                checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx") ||
    116117                checkLayout(str, "xxxx:xx:xx xx:xx:xx.xxx") ||
     118                checkLayout(str, "xxxx/xx/xx xx:xx:xx.xxx") ||
    117119                checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx+xx:00") ||
    118120                checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx-xx:00")) {
Note: See TracChangeset for help on using the changeset viewer.