If the app uses keyboard, I'd consider a text field (a single line text editing element) where user can type using natural language. The field should only allow to type the predefined strings such as This week
, Last month
, Last quarter
, Today
, Yesterday
, Since Tuesday
, etc. and date ranges such as December - May
(for the most recent December to May range), 2015-2020
, 12/22/1990-May/5/2000
, etc.
The user would need to press as few buttons and type as few characters as possible:
- Automatic capitalization. E.g. upon typing
l
(for Last
), the system should automatically correct it to L
.
- The characters that lead to unsupported formats should be prohibited/ignored. That is if user presses the
a
button after entering Dec
, the button press must be ignored as the only possible option is December
.
- The hints on what's possible to type next are also very helpful. Upon typing
j
, the system should offer June
and July
.
- Support natural language features such as references to holidays. Example:
Since Labor Day
.
Examples
1)
The letter z
will likely never appear in the supported formatted string and as such should be completely ignored. Starting the string should be possible with digit or one of the few letters such as t
(for This
, Today
, Tomorrow
, Tuesday
, etc.). If user has already entered y
, the system will only allow for e
as a next character because y
presumably means only Yesterday
.
2)
If user starts with typing l
, then only possible option (I can currently think of) is Last
.
3)
The system should also offer hints on what's possible to type next and allow to select options with vertical arrows and completing the currently entered term with Enter button.
4)
If user has typed j
, the options offered should be June
and July
with June
being the default (first in the list) option. If user hits Enter, then June
is selected. If user types u
and l
next, the system should offer July
as only valid option.
5)
If user types a
, this could mean April
, August
, and After
(e.g. After Labor Day
).
Other thoughts
For clarity, along with the user input, the system should display the actual interpreted date range. For example, if today is December 1, 2021 and user types Since last Friday
, the interpreted date range should be Friday 11/26/2021 - Wednesday 12/1/2021
. The preferred date format should ideally match user's native one.
If the app can support voice input, I'd recommend using it as well for the similar input style. Though correcting such input would require another algorithm. At least, allow user to speak meaningless words such as from
, and
, etc.
Example: the user may say something like from last quarter and until yesterday
. Here, from
, and
, and until
are useless (meaningless) words.
To support as many natural language constructions as possible you may want to first spend some time on collecting and organizing them. And then maybe creating sort of parser off the set of formal declarations.
There are some libraries that already support this kind of input. Though they may not support all variants you may need. Example: https://github.com/argenos/nldates-obsidian.