Update date regex to handles dashes and slashes
This commit is contained in:
parent
54f50a7690
commit
1e3c795935
3 changed files with 5 additions and 2 deletions
|
|
@ -36,6 +36,7 @@
|
||||||
This only has effect interfacing to calc mode in edit amount"
|
This only has effect interfacing to calc mode in edit amount"
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'ledger)
|
:group 'ledger)
|
||||||
|
|
||||||
(defun ledger-split-commodity-string (str)
|
(defun ledger-split-commodity-string (str)
|
||||||
"Split a commoditized amount into two parts"
|
"Split a commoditized amount into two parts"
|
||||||
(let (val
|
(let (val
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@
|
||||||
(eval-when-compile
|
(eval-when-compile
|
||||||
(require 'cl))
|
(require 'cl))
|
||||||
|
|
||||||
|
(defvar ledger-date-regex "\\([0-9]+\\)[/-]\\([0-9]+\\)[/-]\\([0-9]+\\)")
|
||||||
|
|
||||||
(defmacro ledger-define-regexp (name regex docs &rest args)
|
(defmacro ledger-define-regexp (name regex docs &rest args)
|
||||||
"Simplify the creation of a Ledger regex and helper functions."
|
"Simplify the creation of a Ledger regex and helper functions."
|
||||||
(let ((defs
|
(let ((defs
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ within the transaction."
|
||||||
(extents (ledger-find-xact-extents (point)))
|
(extents (ledger-find-xact-extents (point)))
|
||||||
(transaction (buffer-substring (car extents) (cadr extents)))
|
(transaction (buffer-substring (car extents) (cadr extents)))
|
||||||
encoded-date)
|
encoded-date)
|
||||||
(if (string-match "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)" date)
|
(if (string-match ledger-date-regex date)
|
||||||
(setq encoded-date
|
(setq encoded-date
|
||||||
(encode-time 0 0 0 (string-to-number (match-string 3 date))
|
(encode-time 0 0 0 (string-to-number (match-string 3 date))
|
||||||
(string-to-number (match-string 2 date))
|
(string-to-number (match-string 2 date))
|
||||||
|
|
@ -114,7 +114,7 @@ within the transaction."
|
||||||
(ledger-find-slot encoded-date)
|
(ledger-find-slot encoded-date)
|
||||||
(insert transaction "\n")
|
(insert transaction "\n")
|
||||||
(backward-paragraph)
|
(backward-paragraph)
|
||||||
(re-search-forward "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)")
|
(re-search-forward ledger-date-regex)
|
||||||
(replace-match date)
|
(replace-match date)
|
||||||
(re-search-forward "[1-9][0-9]+\.[0-9]+")))
|
(re-search-forward "[1-9][0-9]+\.[0-9]+")))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue