Hello everyone,
I'm looking for a way to provide a custom date interval to an hledger command.
My use case is the following:
I have a CLI tool helping me decide for every week which "budget month" it is part of (e.g., when a week overlaps two months, it decides which month the week belongs to). I don't like splitting weeks, and this is the solution I've come up with.
Now, I would love to use hledger's reporting capabilities with a monthly query hledger --no-conf --file ~/path/to/my-journal.journal incomestatement -p 2024 -M
to reflect this. Right now, the expenses will be tied to their respective month.
Is their any way to achieve this?
Let me know if anything is not clear, I'll be happy to provide more details.
I guess you want to keep the transaction dates accurate. But I suppose you could record adjusted budgeting dates as https://hledger.org/1.52/hledger.html#secondary-dates, and run your budget reports with --date2 ?
Hi,
Thanks for the prompt reply and many more thanks for the awesome tool that is Hledger!
I'm not sure secondary date is what I'm looking for. From what I understand from the page you linked, secondary date allow to link two dates to a single posting.
My goal is not to keep transaction dates accurate.
My goal is to group budget week in their "correct" budget month.
Let's take 2024 as an example. My tool output a Json dividing a year into budget month as I explained earlier.
As you can see, the first week of February starts in January. What I would really want is for Hledger to use this timeframe when doing a query that spans over months (e.g., January runs from 01-01 to 01-28)
I think this implies that you can't or do not want to use '-b' /'-e' with your custom dates. Am I right? If I am - could you elaborate why?
Perhaps something like this would work: hledger run with a script that your tool genrated. Script will contain 12 commands, one per "month", with custom begin/end dates, and perhaps with --total-only
I did not know about the -b/-e flags. I'm currently using -p "start_date..end_date" to specify the date period for my queries. Is there any difference between the two approaches?
With the current output of my tool, I'm able to generate a monthly query that includes the correct weeks. My goal now is to glue the queries together to have a yearly report, divided by my budget month.
EDIT: actually CompoundBalanceCommandSpec does not specify reporting periods, ignore me.
incomestatement is just a thin wrapper around compoundBalanceCommand. I feel like it should be easy to write a new custom script/custom binary (a-la those available in hledger/scripts) that read your periods from args or file, constructs CompoundBalanceCommandSpecwith your custom periods and feeds it to compoundBalanceCommand. See hledger/bin/hledger-report1.hs in the repo for a skeleton code that could be used as a starting point, if you are so inclined.
This is probably easier that trying to add some sort of generic "custom report period spec" to hledger which by necessity would have to be more flexible and more general than what's necessary for your specific case.