Skip to content

Enhancement: Add +/- syntax, (w)eek (m)onth (y)ear, and time support to query :inputs - #8387

Merged
logseq-cldwalker merged 12 commits into
masterfrom
ben/advanced-queries-relative-date-input
Jan 20, 2023
Merged

logseq-cldwalker merged 12 commits into
masterfrom
ben/advanced-queries-relative-date-input

Conversation

@bendyorke

@bendyorke bendyorke commented Jan 18, 2023 •

Copy link
Copy Markdown
Contributor

This refactors db-util/resolve-input to use a multi method like previously discussed with @logseq-cldwalker. There are several things going on in this refactor:

  1. Move all keyword resolvers into distinct multi methods
  2. Add support for simple query-like syntax (+1d, -7d)
  3. Add support for relative weeks/months/years (+1w -3m +2y)
  4. Marks inputs with older syntax as DEPRECATED (only in the codebase, they just translate to the new inputs and re-resolve)
  5. Adds 'support' for other date relatives - currently everything is relative to today, but once this gets merged, I will subsequently add support for the journal date relatives, which should be a single line change (:journal/+3d). I also thought this could very easily support :query/+3d and :current/+3d, but I'm realizing as I'm writing this that the only time those are really applicable are on journal pages, and I'm pretty sure :journal/+3d would suffice in both cases.

Let me know if the namespaces are too abstract, I'm open to changing the inputs to something more readable like +3d-journal or :+3d-journal-day or +3d-from-journal-day, but none of those read right to me. I'm not sure if namespaces are too confusing, but since the day that the query is relative to is kind of like a context, and the rest should function the same, it seemed fitting.

@CLAassistant

CLAassistant commented Jan 18, 2023 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@logseq-cldwalker logseq-cldwalker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendyorke Great work on these input enhancements with date-time math! Back to you for some feedback and to get CI to green

Let me know if the namespaces are too abstract, I'm open to changing the inputs to something more readable like +3d-journal or :+3d-journal-day or +3d-from-journal-day, but none of those read right to me.

I find the emphasis on date math first more readable as suggested by #7866. But maybe having the terser +/- changes that. How about we ask non-engineers about it? If we do decide to put the date-time type first, I'd advocate for - as the separator over / as the latter seems less readable

(let [relative-to (case (or (namespace input) "today")
"today" (t/today))
[_ offset-direction offset offset-unit offset-ms?] (re-find #"^([+-])(\d+)([dwmy])(-ms)?$" (name input))
offset-fn (case offset-direction "+" t/plus "-" t/minus)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm digging the explicitness of the syntax we agreed to. This sets us up nicely in the future to support chaining these down the road :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by chaining these?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want to scope creep this PR hehe, but down the road we could get asks to add or subtract multiple date ranges so +1w+1d or +1y-1w would naturally fit

@logseq-cldwalker logseq-cldwalker changed the title Refactor resolve-input to use simple query relative date syntax Enhancement: Add +/- syntax and (w)eek, (m)onth and (y)ear support to query :inputs Jan 18, 2023
@logseq-cldwalker

Copy link
Copy Markdown
Collaborator

@bendyorke Changed title since PR titles get used in changelogs so we try to make them as readable for users as possible. Feel free to reword

@bendyorke

Copy link
Copy Markdown
Contributor Author

New PR title is better than I could have come up with 😂 good to know they're used in changelogs, I'll try to be more explicit in the future. Please feel free to rename anytime you'd like a change, I appreciate it!

@Bad3r Bad3r added this to the 0.8.17 milestone Jan 19, 2023
@bendyorke bendyorke changed the title Enhancement: Add +/- syntax and (w)eek, (m)onth and (y)ear support to query :inputs Enhancement: Add +/- syntax and (w)eek, (m)onth and (y)ear and time support to query :inputs Jan 20, 2023
@bendyorke bendyorke changed the title Enhancement: Add +/- syntax and (w)eek, (m)onth and (y)ear and time support to query :inputs Enhancement: Add +/- syntax, (w)eek (m)onth (y)ear, and time support to query :inputs Jan 20, 2023
@bendyorke

Copy link
Copy Markdown
Contributor Author

@logseq-cldwalker I think I've addressed all of your concerns. LMK if there's anything else, once this get's merged in I'll update the docs graph with info about these :D

@logseq-cldwalker

Copy link
Copy Markdown
Collaborator

@logseq-cldwalker I think I've addressed all of your concerns. LMK if there's anything else, once this get's merged in I'll update the docs graph with info about these :D

Sweet. Taking a look. Can you get CI to green in the meantime? There's a new version of @logseq/nbb-logseq for the related lint task

@logseq-cldwalker logseq-cldwalker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendyorke Thanks for addressing feedback and adding time syntax as well! One product question on the new feature and waiting for a green CI

- end: will return the time at the end of the day [23:59:59.999]
- HHMM: will return the specified time at the turn of the minute [HH:MM:00.000]
- HHMMSS: will return the specified time at the turm of the second [HH:MM:SS.000]
- HHMMSSmmm: will return the specified time at the turn of the millisecond [HH:MM:SS.mmm]

@logseq-cldwalker logseq-cldwalker Jan 20, 2023 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Not it" for millisecond bugs 😛

;; :Xd, :Xd-before, :Xd-before-ms, :Xd-after, :Xd-after-ms
(resolve-keyword-input db (old->new-relative-date-format input) opts))
(re-find #"^[+-]\d+[dwmy]?$" (name input)) :relative-date
(re-find #"^[+-]\d+[dwmy]-(ms|start|end|\d{2}|\d{4}|\d{6}|\d{9})?$" (name input)) :relative-date-time

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be helpful to give some syntactic consistency to the user e.g. end them all in -ms or prefix these with time e.g. 1d-time-ms? There's no consistent word or characters indicating this is a time value

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more on this, this doesn't need to block this PR. We can adjust the syntax before release as needed

:where [?b :block/page ?bp]
[?bp :block/name ?current-page]]}
{:current-page-fn nil})))
":current-page input fails gracefully when not present")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this confusing as it's not failing but rather not resolving the input. I'm happy to tweak this wording later

@logseq-cldwalker logseq-cldwalker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendyorke Thanks for all the great query :inputs features you've added! 👍 🙌 :shipit: Looks like there's just a nbb-logseq bump to get the last test passing. I can do that in a bit if you don't get to it

@logseq-cldwalker
logseq-cldwalker merged commit 090d25b into master Jan 20, 2023
@logseq-cldwalker
logseq-cldwalker deleted the ben/advanced-queries-relative-date-input branch January 20, 2023 21:34
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 1, 2026
…te-input

Enhancement: Add +/- syntax, (w)eek (m)onth (y)ear, and time support to query :inputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants