diff --git a/js/ffs.ts b/js/ffs.ts index 241e9af0f..3ee032071 100644 --- a/js/ffs.ts +++ b/js/ffs.ts @@ -190,6 +190,14 @@ export function ffs_construct_query( ) return `(newer:"{{date:${val}}}")`; return `(newer:"${val}")`; + case "older": + if ( + condition.val.match( + /^-?\d+ ?(seconds?|minutes?|hours?|days?|weeks?|months?|years?)?$/ + ) + ) + return `(if: timestamp() <= date("{{date:${val}}}"))`; + return `(if: timestamp() <= date("${val}"))`; case "user": return `(user:"${val}")`; case "uid": @@ -252,6 +260,8 @@ export function ffs_construct_query( return quote_comment_str(`id:${quotes(condition.val)}`); case "newer": return quote_comment_str(`newer:${quotes(condition.val)}`); + case "older": + return quote_comment_str(`older:${quotes(condition.val)}`); case "user": return quote_comment_str(`user:${quotes(condition.val)}`); case "uid": diff --git a/js/ffs/ffs.pegjs b/js/ffs/ffs.pegjs index c0c2e7cd9..a05a73cd9 100644 --- a/js/ffs/ffs.pegjs +++ b/js/ffs/ffs.pegjs @@ -104,7 +104,7 @@ osm_type = "node" / "way" / "relation" meta // TODO? - = x:("user" / "uid" / "newer" / "id") _ ":" _ y:string + = x:("user" / "uid" / "newer" / "older" / "id") _ ":" _ y:string { return { query:"meta", meta:x, val:y } } free_form diff --git a/tests/test.ffs.ts b/tests/test.ffs.ts index 528dec3a2..707bfbae7 100644 --- a/tests/test.ffs.ts +++ b/tests/test.ffs.ts @@ -242,6 +242,19 @@ describe("ide.ffs", () => { `node(newer:"date:1day")(bbox);${out_str}` ); }); + // older + it("older", async () => { + // regular + let search = 'older:"2000-01-01T01:01:01Z" and type:node'; + await expect(construct_query(search)).resolves.to.equal( + `node(if: timestamp() <= date("2000-01-01T01:01:01Z"))(bbox);${out_str}` + ); + // relative + search = "older:1day and type:node"; + await expect(construct_query(search)).resolves.to.equal( + `node(if: timestamp() <= date("date:1day"))(bbox);${out_str}` + ); + }); // user it("user", async () => { // user name