Ignore:
Timestamp:
2014-07-09T22:15:41+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #10121 - Add a new look-and-feel preference to display ISO 8601 dates globally

Location:
trunk/src/org/openstreetmap/josm/io
Files:
8 edited

Legend:

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

    r7012 r7299  
    1414import org.openstreetmap.josm.data.osm.history.HistoryRelation;
    1515import org.openstreetmap.josm.data.osm.history.HistoryWay;
    16 import org.openstreetmap.josm.tools.DateUtils;
     16import org.openstreetmap.josm.tools.date.DateUtils;
    1717import org.xml.sax.Attributes;
    1818import org.xml.sax.Locator;
  • trunk/src/org/openstreetmap/josm/io/ChangesetClosedException.java

    r6890 r7299  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.text.DateFormat;
    76import java.text.ParseException;
    8 import java.text.SimpleDateFormat;
    97import java.util.Date;
    10 import java.util.Locale;
    118import java.util.regex.Matcher;
    129import java.util.regex.Pattern;
    1310
    1411import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.tools.date.DateUtils;
    1513
    1614/**
     
    7775        if (m.matches()) {
    7876            changesetId = Long.parseLong(m.group(1));
    79             // Example: "2010-09-07 14:39:41 UTC". Always parsed with US locale regardless
    80             // of the current locale in JOSM
    81             DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.US);
    8277            try {
    83                 closedOn = formatter.parse(m.group(2));
     78                closedOn = DateUtils.newOsmApiDateTimeFormat().parse(m.group(2));
    8479            } catch(ParseException ex) {
    8580                Main.error(tr("Failed to parse date ''{0}'' replied by server.", m.group(2)));
  • trunk/src/org/openstreetmap/josm/io/ChangesetQuery.java

    r7012 r7299  
    99import java.text.MessageFormat;
    1010import java.text.ParseException;
    11 import java.text.SimpleDateFormat;
    1211import java.util.Arrays;
    1312import java.util.Collection;
     
    2423import org.openstreetmap.josm.tools.CheckParameterUtil;
    2524import org.openstreetmap.josm.tools.Utils;
     25import org.openstreetmap.josm.tools.date.DateUtils;
    2626
    2727public class ChangesetQuery {
     
    9797
    9898    /**
    99      * Replies true if this query is restricted to user whom we only know the user name
    100      * for.
    101      *
    102      * @return true if this query is restricted to user whom we only know the user name
    103      * for
     99     * Replies true if this query is restricted to user whom we only know the user name for.
     100     *
     101     * @return true if this query is restricted to user whom we only know the user name for
    104102     */
    105103    public boolean isRestrictedToPartiallyIdentifiedUser() {
     
    206204     * @throws IllegalArgumentException thrown if createdBefore is null
    207205     */
    208     public ChangesetQuery closedAfterAndCreatedBefore(Date closedAfter, Date createdBefore ) throws IllegalArgumentException{
     206    public ChangesetQuery closedAfterAndCreatedBefore(Date closedAfter, Date createdBefore ) throws IllegalArgumentException {
    209207        CheckParameterUtil.ensureParameterNotNull(closedAfter, "closedAfter");
    210208        CheckParameterUtil.ensureParameterNotNull(createdBefore, "createdBefore");
     
    277275                sb.append("&");
    278276            }
    279             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
     277            DateFormat df = DateUtils.newIsoDateTimeFormat();
    280278            sb.append("time").append("=").append(df.format(closedAfter));
    281279            sb.append(",").append(df.format(createdBefore));
     
    284282                sb.append("&");
    285283            }
    286             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
     284            DateFormat df = DateUtils.newIsoDateTimeFormat();
    287285            sb.append("time").append("=").append(df.format(closedAfter));
    288286        }
     
    315313    public static class ChangesetQueryUrlException extends Exception {
    316314
    317         public ChangesetQueryUrlException() {
    318             super();
    319         }
    320 
    321         public ChangesetQueryUrlException(String arg0, Throwable arg1) {
    322             super(arg0, arg1);
    323         }
    324 
    325         public ChangesetQueryUrlException(String arg0) {
    326             super(arg0);
    327         }
    328 
    329         public ChangesetQueryUrlException(Throwable arg0) {
    330             super(arg0);
     315        /**
     316         * Constructs a new {@code ChangesetQueryUrlException} with the specified detail message.
     317         *
     318         * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method.
     319         */
     320        public ChangesetQueryUrlException(String message) {
     321            super(message);
     322        }
     323
     324        /**
     325         * Constructs a new {@code ChangesetQueryUrlException} with the specified cause and a detail message of
     326         * <tt>(cause==null ? null : cause.toString())</tt> (which typically contains the class and detail message of <tt>cause</tt>).
     327         *
     328         * @param  cause the cause (which is saved for later retrieval by the {@link #getCause()} method).
     329         *         (A <tt>null</tt> value is permitted, and indicates that the cause is nonexistent or unknown.)
     330         */
     331        public ChangesetQueryUrlException(Throwable cause) {
     332            super(cause);
    331333        }
    332334    }
     
    335337        protected int parseUid(String value) throws ChangesetQueryUrlException {
    336338            if (value == null || value.trim().isEmpty())
    337                 throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", "uid",value));
     339                throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", "uid", value));
    338340            int id;
    339341            try {
    340342                id = Integer.parseInt(value);
    341343                if (id <= 0)
    342                     throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", "uid",value));
     344                    throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", "uid", value));
    343345            } catch(NumberFormatException e) {
    344                 throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", "uid",value));
     346                throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", "uid", value));
    345347            }
    346348            return id;
     
    349351        protected boolean parseBoolean(String value, String parameter) throws ChangesetQueryUrlException {
    350352            if (value == null || value.trim().isEmpty())
    351                 throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter,value));
     353                throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter, value));
    352354            switch (value) {
    353355            case "true":
     
    356358                return false;
    357359            default:
    358                 throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter,value));
     360                throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter, value));
    359361            }
    360362        }
     
    362364        protected Date parseDate(String value, String parameter) throws ChangesetQueryUrlException {
    363365            if (value == null || value.trim().isEmpty())
    364                 throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter,value));
     366                throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter, value));
    365367            if (value.endsWith("Z")) {
    366                 // OSM API generates date strings we time zone abbreviation "Z" which Java SimpleDateFormat
     368                // OSM API generates date strings with time zone abbreviation "Z" which Java SimpleDateFormat
    367369                // doesn't understand. Convert into GMT time zone before parsing.
    368370                //
    369371                value = value.substring(0,value.length() - 1) + "GMT+00:00";
    370372            }
    371             DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
     373            DateFormat formatter = DateUtils.newIsoDateTimeFormat();
    372374            try {
    373375                return formatter.parse(value);
    374376            } catch(ParseException e) {
    375                 throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter,value));
     377                throw new ChangesetQueryUrlException(tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter, value));
    376378            }
    377379        }
     
    384386                return new Date[]{parseDate(dates[0], "time")};
    385387            else if (dates.length == 2)
    386                 return new Date[]{parseDate(dates[0], "time"),parseDate(dates[1], "time")};
     388                return new Date[]{parseDate(dates[0], "time"), parseDate(dates[1], "time")};
    387389            return null;
    388390        }
     
    435437                    try {
    436438                        csQuery.inBbox(new Bounds(entry.getValue(), ","));
    437                     } catch(IllegalArgumentException e) {
     439                    } catch (IllegalArgumentException e) {
    438440                        throw new ChangesetQueryUrlException(e);
    439441                    }
     
    479481         * @throws ChangesetQueryUrlException if the query string doesn't represent a legal query for changesets
    480482         */
    481         public ChangesetQuery parse(String query) throws  ChangesetQueryUrlException{
     483        public ChangesetQuery parse(String query) throws ChangesetQueryUrlException {
    482484            if (query == null)
    483485                return new ChangesetQuery();
     
    485487            if (query.isEmpty())
    486488                return new ChangesetQuery();
    487             Map<String,String> queryParams  = createMapFromQueryString(query);
     489            Map<String,String> queryParams = createMapFromQueryString(query);
    488490            return createFromMap(queryParams);
    489491        }
  • trunk/src/org/openstreetmap/josm/io/NmeaReader.java

    r7082 r7299  
    1818import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
    1919import org.openstreetmap.josm.data.gpx.WayPoint;
    20 import org.openstreetmap.josm.tools.DateUtils;
     20import org.openstreetmap.josm.tools.date.DateUtils;
    2121
    2222/**
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r7082 r7299  
    1818import org.openstreetmap.josm.data.osm.User;
    1919import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    20 import org.openstreetmap.josm.tools.DateUtils;
    2120import org.openstreetmap.josm.tools.XmlParsingException;
     21import org.openstreetmap.josm.tools.date.DateUtils;
    2222import org.xml.sax.Attributes;
    2323import org.xml.sax.InputSource;
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r7081 r7299  
    3939import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    4040import org.openstreetmap.josm.tools.CheckParameterUtil;
    41 import org.openstreetmap.josm.tools.DateUtils;
     41import org.openstreetmap.josm.tools.date.DateUtils;
    4242
    4343/**
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r7033 r7299  
    1818import org.openstreetmap.josm.data.osm.UserInfo;
    1919import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    20 import org.openstreetmap.josm.tools.DateUtils;
    2120import org.openstreetmap.josm.tools.XmlParsingException;
     21import org.openstreetmap.josm.tools.date.DateUtils;
    2222import org.w3c.dom.Document;
    2323import org.w3c.dom.Node;
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r7236 r7299  
    2828import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
    2929import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    30 import org.openstreetmap.josm.tools.DateUtils;
     30import org.openstreetmap.josm.tools.date.DateUtils;
    3131
    3232/**
Note: See TracChangeset for help on using the changeset viewer.