Ignore:
Timestamp:
2016-01-10T13:48:42+01:00 (4 years ago)
Author:
simon04
Message:

Refactoring: introduce UncheckedParseException

In addition, DateUtils#fromString does no longer return "now" when
date cannot be parsed, but throws an UncheckedParseException instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r9383 r9385  
    1818import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
     20import org.openstreetmap.josm.tools.UncheckedParseException;
    2021
    2122/**
     
    6667     * @param str The XML date as string
    6768     * @return The date
    68      */
    69     public static synchronized Date fromString(String str) {
     69     * @throws UncheckedParseException if the date does not match any of the supported date formats
     70     */
     71    public static synchronized Date fromString(String str) throws UncheckedParseException {
    7072        return new Date(tsFromString(str));
    7173    }
     
    7577     * @param str The XML date as string
    7678     * @return The date in milliseconds since epoch
    77      */
    78     public static synchronized long tsFromString(String str) {
     79     * @throws UncheckedParseException if the date does not match any of the supported date formats
     80     */
     81    public static synchronized long tsFromString(String str) throws UncheckedParseException {
    7982        // "2007-07-25T09:26:24{Z|{+|-}01:00}"
    8083        if (checkLayout(str, "xxxx-xx-xxTxx:xx:xxZ") ||
     
    130133            return XML_DATE.newXMLGregorianCalendar(str).toGregorianCalendar().getTimeInMillis();
    131134        } catch (Exception ex) {
    132             return System.currentTimeMillis();
     135            throw new UncheckedParseException("The date string (" + str + ") could not be parsed.");
    133136        }
    134137    }
Note: See TracChangeset for help on using the changeset viewer.