Skip to content

Commit

Permalink
Sort dates without leading 0 naturally
Browse files Browse the repository at this point in the history
E.g. sort 2022/5/7 as expected.  Previously one had to write 2022/05/07 to do
the sorting reliably.  Note the zeros!
  • Loading branch information
marcowahl authored and bcc32 committed Mar 24, 2024
1 parent 51d1e7a commit fb09516
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ledger-sort.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
;;; Code:
(require 'ledger-regex)
(require 'ledger-navigate)
(require 'ledger-xact)

(defun ledger-sort-find-start ()
"Find the beginning of a sort region."
Expand Down Expand Up @@ -59,8 +60,12 @@
(insert "\n; Ledger-mode: End sort\n\n"))

(defun ledger-sort-startkey ()
"Return the date portion of the current line, for use in sorting."
(buffer-substring-no-properties (point) (+ 10 (point))))
"Return a numeric sort key based on the date of the xact beginning at point."
;; Can use `time-convert' to return an integer instead of a floating-point
;; number, starting in Emacs 27.
(float-time
(ledger-parse-iso-date
(buffer-substring-no-properties (point) (+ 10 (point))))))

(defun ledger-sort-region (beg end)
"Sort the region from BEG to END in chronological order."
Expand Down

0 comments on commit fb09516

Please sign in to comment.