Skip to content

Support date predicates in advanced expr: queries #2672

Description

@rickswe

Hello, I recently came across a limitation in hledger while trying to build a more advanced expr: query involving dates.

For reference, Ledger supports date expressions in value expressions, including comparisons such as date < [tomorrow] and date >= [tomorrow]: Ledger CLI — Date Expressions

I'd like expr: queries to support date predicates as part of more advanced boolean expressions.

For example:

hledger is -p "2023 to 2028" --forecast='tomorrow..2028' -Y -3 -S \
    expr:'(date:<tomorrow AND NOT tag:future) OR (date:>=tomorrow AND tag:future)'

The intended result is:

  • Before tomorrow: include transactions not tagged future.
  • Tomorrow onward: include only transactions tagged future.

I understand this particular forecasting example can be worked around by adjusting the periodic/budget entries and controlling the forecast period. However, I still think being able to apply different query conditions to different date ranges in a single expression would be useful more generally.

Ideally, date predicates such as these could be combined normally with AND, OR, NOT, and parentheses:

date:<today
date:<=today
date:>=tomorrow
date:>2027-01-01

Related: #2177 and #2178 cover the date/OR behavior that led to the current restriction, while #2095 discusses making expr: queries more expressive in general.

Thank you for all the work on hledger.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WISHSome kind of improvement request or proposal.queriesFiltering options, query arguments..

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions