Hi all,

I recently started using ledger and ledger-mode and ran into an issue that looks like a bug to me, but before I create a Github issue, I would like to be sure.

The tl;dr of it is that ledger-mode uses the value of `date-format` set in `~/.ledgerrc` for reading a date from the user in `ledger-add-transaction`, which leads to an error if the ledger-mode option `ledger-default-date-format` is not set to the same string (and consequently the transaction dates in the ledger don't use the this format.)

The ledger man page says that `--date-format` is for *printing* dates, and that's indeed how ledger seems to behave, because it used my specified date format when printing reports, even though the transaction dates in the ledger use the default YYYY/MM/DD format.

So I think ledger-mode should not use ledger's `--date-format` for *reading* dates from the user and shouldn't require that transaction dates in the ledger use this format. Unless of course I'm overlooking something. :-)

The longer version:

In my ledger file, transaction dates are written as YYYY/MM/DD, because that's the default format and it enables ledger-mode to keep the transactions in chronological order. The default date format in register reports, however, is YY-MM-DD, which I find somewhat confusing, especially because the year is reduced to two digits.

So I looked through the docs and found the ledger option `--date-format`, which, as the man page states, is used to print dates.

I added that option to `~/.ledgerrc` and all was fine, at first. However, when I reopened the ledger file in Emacs the next day and tried to add a new transaction with `ledger-add-transaction`, I was greeted with a wrong-type-argument error.

Turns out that ledger-mode, when asking the user for a date, obtains this date from `org-read-date` in Emacs internal time format but then converts it to a string with `format-time-string` using the ledger setting for `--date-format`. This string is then passed to `ledger-parse-iso-date`, which fails because the date isn't in iso format. This failure then leads to the wrong-type-argument error in `ledger-time-less-p` (called from `ledger-xact-find-slot`), because it cannot handle string values.

If I set `ledger-default-date-format` to the same string as ledger's `--date-format` option and format the dates in the ledger in the same manner, the error does not occur, but sorting doesn't work and the new entry is simply put at the end of the ledger file. (Though I guess that may actually not be a bug but intended behaviour).

It's the function `ledger-format-date` that converts the user-provided date info to a string, and it seems that it shouldn't use ledger`s `--date-format` option to do so, at least not when called from `ledger-add-transaction`. Instead, `ledger-add-transaction` should use a date format that's compatible with the transaction date format in the ledger (which I guess is the value of `ledger-default-date-format`).

So is my assessment right? Should I open a Github issue, or is this intended behaviour and am I overlooking something?

TIA

Joost


--
Joost Kremers
Life has its moments

--

--- You received this message because you are subscribed to the Google Groups "Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/877dwydgf6.fsf%40fastmail.fm.

Reply via email to