Changeset 17988 in josm


Ignore:
Timestamp:
2021-07-10T23:26:59+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21021 - proper fix of "newer" keyword, handling both formats (date and duration)

Location:
trunk
Files:
4 edited

Legend:

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

    r17982 r17988  
    4646import org.openstreetmap.josm.tools.UncheckedParseException;
    4747import org.openstreetmap.josm.tools.Utils;
     48import org.openstreetmap.josm.tools.date.DateUtils;
    4849
    4950/**
     
    243244    }
    244245
    245     static String date(String humanDuration, LocalDateTime from) {
     246    static String date(String dateOrHumanDuration, LocalDateTime from) {
     247        try {
     248            return DateUtils.parseInstant(dateOrHumanDuration).toString();
     249        } catch (UncheckedParseException e) {
     250            Logging.trace(e);
     251        }
     252        return duration(dateOrHumanDuration, from);
     253    }
     254
     255    static String duration(String humanDuration, LocalDateTime from) {
    246256        // Convert to ISO 8601. Replace months by X temporarily to avoid conflict with minutes
    247257        String duration = humanDuration.toLowerCase(Locale.ENGLISH).replace(" ", "")
  • trunk/src/org/openstreetmap/josm/tools/SearchCompilerQueryWizard.java

    r17982 r17988  
    104104            final String value = ((SearchCompiler.KeyValue) match).getValue();
    105105            if ("newer".equals(key)) {
    106                 return "(newer:" + quote(value) + ")";
     106                return "(newer:" + quote("{{date:" + value + "}}") + ")";
    107107            }
    108108            return "[~" + quote(key) + "~" + quote(value) + "]";
  • trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java

    r17336 r17988  
    120120    @Test
    121121    public void testDateNewer() {
    122         final String query = getExpandedQuery("type:node and newer:3minutes");
     122        String query = getExpandedQuery("type:node and newer:3minutes");
    123123        String statement = query.substring(query.indexOf("node(newer:\"") + 12, query.lastIndexOf("\");"));
     124        assertNotNull(DateUtils.fromString(statement));
     125
     126        query = getExpandedQuery("type:node and newer:\"2021-05-30T20:00:00Z\"");
     127        statement = query.substring(query.indexOf("node(newer:\"") + 12, query.lastIndexOf("\");"));
    124128        assertNotNull(DateUtils.fromString(statement));
    125129    }
  • trunk/test/unit/org/openstreetmap/josm/tools/SearchCompilerQueryWizardTest.java

    r17982 r17988  
    221221    @Test
    222222    void testNewer() {
    223         assertQueryEquals("  nwr(newer:\"2021-05-30T20:00:00Z\");\n",
     223        assertQueryEquals("  nwr(newer:\"{{date:3minutes}}\");\n",
     224                "newer:3minutes");
     225
     226        assertQueryEquals("  nwr(newer:\"{{date:2021-05-30T20:00:00Z}}\");\n",
    224227                "newer:\"2021-05-30T20:00:00Z\"");
    225228    }
Note: See TracChangeset for help on using the changeset viewer.