搜索引擎:相对日期条件的查询语法设计

Search engine: design of query syntax for relative date condition

我正在为接受相对日期作为附加条件的搜索引擎设计查询语法,例如 since 2 days ago or since 4 days ago until 2 天前。我的搜索引擎将它们作为纯字符串接受,类似于 since:4_days_ago until:2_days_ago,将在一个简单的文本框中输入。

但我不确定这些语法在语法上是否正确以及我的客户是否易于使用。所以这是我的问题:

  1. 是否有任何现有服务具有类似的语法来指定相对日期?这对我来说将是一个很好的参考。
  2. 有任何改进 syntax/grammar 的想法或对设计有很好的参考吗?

任何其他建议或意见也将不胜感激。

Programmers.SE 有类似的问题(不能将此标记为重复):https://softwareengineering.stackexchange.com/questions/78795/best-representation-for-relative-dates-durations

我在这里引用它:

Not a standard, but a convention used by FogBugz and Jira (both bugtrackers) is to enter durations in simple terms like 2d for 2 days, 3w for 3 weeks, 1m for 1 month, etc.

The convention could be extended for dates and periods relative to some other date (usually the current date I presume).

  • today + 2 days: +2d
  • today a year back: -1y
  • next Sunday: +1Sun (use the day-of-week names which should of course be locale specific)
  • the 15 of next month: +m15, or +1m15
  • 20th of the previous: -1m20
  • last of next month: +1mL (L signifies last day of the month/week/quarter/semester/year, used a capital L to distinguish it from the number 1 in many fonts)

To specifiy periods instead of just dates, you could double up the letters:

  • all of last month: -1mm
  • all of next week: +1ww
  • all of last year: -1yy

To specify a period between two specific relative dates:

  • 15 of next month to 20th of month after that: +m15..+2m20
  • all of last month could then also be specified as: -1m1..-1mL

Parsing could become an interesting business...