ledger-mode icon indicating copy to clipboard operation
ledger-mode copied to clipboard

Sort dates without leading 0 naturally

Open marcowahl opened this issue 2 years ago • 3 comments

E.g. sort 2022/5/7 as expected. Previously one had to write 2022/05/07 to do the sorting reliably. Note the zeros!

The price for the fix of the sorting is the work to parse the date for each record.

marcowahl avatar May 17 '22 09:05 marcowahl

Or you could substitute single-digits for zero-padded ones if parsing is costly?

purcell avatar May 20 '22 16:05 purcell

Yes that could be done.

The patch is thought to eliminate confusion when the user ledger-sorts a ledger with some dates without leading zeros. The patch helps me and I can imagine that it can help others.

For me the parsing is not a time or performance issue. Possibly it is for some people.

I think it's a correctness over speed question here.

marcowahl avatar May 25 '22 17:05 marcowahl

This is still useful, personally I don't think that the performance is an issue here, sorting incorrectly but faster doesn't sound like a desirable outcome. LGTM. cc: @bcc32

jdek avatar Mar 19 '24 20:03 jdek

I've gone ahead and rebased the PR, and benchmarked the performance with the following Lisp code in my personal ledger file (I have a ledger file with 10,000 xacts, total size 2.5MB):

(benchmark-run 10 (ledger-sort-buffer))

Before:

(15.29602 3 2.851102999999995)

After:

(16.228317 3 2.797007000000008)

So, it looks like a 6% slowdown in the overall sorting routine, which seems fine to me?

On a smaller file with just 3 xacts (and running ledger-sort-buffer 1000 times instead), I got before:

(0.7417469999999999 0 0.0)

and after:

(0.763527 0 0.0)

so only a 3% slowdown there.

@purcell, if you agree, I'll go ahead and rebase/squash this onto master.

bcc32 avatar Mar 23 '24 22:03 bcc32

Yeah, that's totally fine IMO.

purcell avatar Mar 24 '24 11:03 purcell