Changeset 9701 in josm for trunk


Ignore:
Timestamp:
2016-01-31T16:17:34+01:00 (8 years ago)
Author:
simon04
Message:

fix #12465 - Search dialog validation: fix UncheckedParseException

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r9693 r9701  
    3939import org.openstreetmap.josm.tools.Geometry;
    4040import org.openstreetmap.josm.tools.Predicate;
     41import org.openstreetmap.josm.tools.UncheckedParseException;
    4142import org.openstreetmap.josm.tools.Utils;
    4243import org.openstreetmap.josm.tools.date.DateUtils;
     
    177178                            String rangeA1 = rangeA[0].trim();
    178179                            String rangeA2 = rangeA[1].trim();
    179                             // if min timestap is empty: use lowest possible date
    180                             long minDate = DateUtils.fromString(rangeA1.isEmpty() ? "1980" : rangeA1).getTime();
    181                             // if max timestamp is empty: use "now"
    182                             long maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.fromString(rangeA2).getTime();
     180                            final long minDate;
     181                            final long maxDate;
     182                            try {
     183                                // if min timestap is empty: use lowest possible date
     184                                minDate = DateUtils.fromString(rangeA1.isEmpty() ? "1980" : rangeA1).getTime();
     185                            } catch (UncheckedParseException ex) {
     186                                throw new ParseError(tr("Cannot parse timestamp ''{0}''", rangeA1), ex);
     187                            }
     188                            try {
     189                                // if max timestamp is empty: use "now"
     190                                maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.fromString(rangeA2).getTime();
     191                            } catch (UncheckedParseException ex) {
     192                                throw new ParseError(tr("Cannot parse timestamp ''{0}''", rangeA2), ex);
     193                            }
    183194                            return new TimestampRange(minDate, maxDate);
    184195                        } else {
  • trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java

    r9373 r9701  
    2424import org.openstreetmap.josm.data.osm.Way;
    2525import org.openstreetmap.josm.data.osm.WayData;
     26import org.openstreetmap.josm.tools.date.DateUtils;
    2627
    2728/**
     
    381382    }
    382383
    383     @Test
    384     public void testFooTypeBar() throws Exception {
     384    /**
     385     * Compiles "foo type bar" and tests the parse error message
     386     */
     387    @Test
     388    public void testFooTypeBar() {
    385389        try {
    386390            SearchCompiler.compile("foo type bar");
     
    390394        }
    391395    }
     396
     397    /**
     398     * Search for primitive timestamps.
     399     * @throws ParseError if an error has been encountered while compiling
     400     */
     401    @Test
     402    public void testTimestamp() throws ParseError {
     403        final Match search = SearchCompiler.compile("timestamp:2010/2011");
     404        final Node n1 = new Node();
     405        n1.setTimestamp(DateUtils.fromString("2010-01-22"));
     406        assertTrue(search.match(n1));
     407        n1.setTimestamp(DateUtils.fromString("2016-01-22"));
     408        assertFalse(search.match(n1));
     409    }
    392410}
Note: See TracChangeset for help on using the changeset viewer.