A User's view of Hledger

Learning about hledger

Getting smart about dates

The way hledger handles dates is impressive.

In particular, I think of smart dates, which I was reminded of a couple of weeks ago when I mistyped a date. The context was that I was using the “add” command to add a transaction. When I was prompted to enter a date, I meant to type “3-30” but accidentally entered “3.-30” instead. I received the helpful message:

A valid hledger smart date is required. Eg: 2022-08-30, 8/30, 30, yesterday.

When I saw the word “yesterday” in the above message, three things happened.

First, I thought about the Beatles’ song with the same name, and this inspired last week’s blog post. Somehow, I doubt that I was the first to create a song about plain text accounting, but there can’t be too many others who wrote one before me!

Second, it made me realize that I needed to learn more about smart dates. That is, I suppose that I had once known about “yesterday” being an option as a smart date, but I had forgotten about it. What else is there I might have forgotten about or perhaps not ever known?

One great place to find the answer is the hledger documentation. But what if you are looking for more?

In my search I stumbled across the Hldeger.Data.Dates page. If you want to get an idea of what is happening behind the scenes with smart dates, this page has a wealth of information. Some of it I don’t understand due to my unfamiliarity with the Haskell programming language. However, there is still much that is accessible even if you don’t know anything about writing Haskell code, like me.

For example, one thing I discovered is that I can use the following when prompted for a date:

-3 days

The result of the above, as you have probably guessed, is that hledger processes “-3 days” and inserts whatever date was 3 days ago.

Neat stuff, and I plan to spend some more time looking at smart dates to see what else might be useful.

Third, and finally, looking at hledger smart dates made me wonder if I have a topic for a new hledger fan video. That is, I would like to do some more research, pick out the most salient points, and create a video explaining them. Stay tuned!