Changeset 1721 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-07-02T18:02:27+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r1425 r1721 7 7 import java.text.SimpleDateFormat; 8 8 import java.util.Date; 9 import java.util.regex.Pattern; 9 10 import java.awt.Color; 10 11 … … 36 37 */ 37 38 public final static SimpleDateFormat GPXTIMEFMT = 38 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); // ignore timezone 39 public final static SimpleDateFormat GPXTIMEFMT2 = 40 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone 39 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); 40 public final static SimpleDateFormat GPXTIMEFMT_nofrac = 41 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); 42 public final static SimpleDateFormat GPXTIMEFMT_tz = 43 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 44 public final static SimpleDateFormat GPXTIMEFMT_tz_nofrac = 45 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); 41 46 42 public void setTime() { 47 private final static Pattern colontz = Pattern.compile(".*[+-][0-9][0-9]:[0-9][0-9]\\z"); 48 private final static Pattern colontzreplacement = Pattern.compile("([+-][0-9][0-9]):([0-9][0-9])\\z"); 49 50 public void setTime() { 43 51 if (! attr.containsKey("time")) { 44 52 return; 45 53 } 46 Date d = GPXTIMEFMT.parse(attr.get("time").toString(), new ParsePosition(0)); 54 String timestring = attr.get("time").toString(); 55 56 /* make the string timzeone be conanonical - unfortunately the allowed timezone in a 57 * GPX is Z or +/-hh:mm whereas in simpledateformat it is +/-hhmm only (no colon) 58 * If no timezone is given, the time will be interpreted as local time by parse. */ 59 if (timestring.substring(timestring.length() - 1).equals("Z")) { 60 timestring = timestring.substring(0, timestring.length() - 1) + "+0000"; 61 } else if (colontz.matcher(timestring).matches()) { 62 timestring = colontzreplacement.matcher(timestring).replaceFirst("$1$2"); 63 } 64 Date d = GPXTIMEFMT_tz.parse(timestring, new ParsePosition(0)); 47 65 if (d == null) { 48 d = GPXTIMEFMT2.parse(attr.get("time").toString(), new ParsePosition(0)); 66 d = GPXTIMEFMT_tz_nofrac.parse(timestring, new ParsePosition(0)); 67 if (d == null) { 68 /* try without a zimezone indication */ 69 d = GPXTIMEFMT.parse(timestring, new ParsePosition(0)); 70 if (d == null) { 71 d = GPXTIMEFMT_nofrac.parse(timestring, new ParsePosition(0)); 72 } 73 // date has parsed in local time, and been adjusted to UTC by parse 74 } 49 75 } 50 76 if (d != null /* parsing ok */) { 51 77 time = d.getTime() / 1000.0; /* ms => seconds */ 52 78 } 53 } 54 79 } 55 80 /** 56 81 * Convert a time stamp of the waypoint from the <cmt> or <desc> field
Note:
See TracChangeset
for help on using the changeset viewer.