Update date regex to handles dashes and slashes

This commit is contained in:
Craig Earls 2013-02-27 10:07:03 -07:00
parent 54f50a7690
commit 1e3c795935
3 changed files with 5 additions and 2 deletions

View file

@ -36,6 +36,7 @@
This only has effect interfacing to calc mode in edit amount"
:type 'boolean
:group 'ledger)
(defun ledger-split-commodity-string (str)
"Split a commoditized amount into two parts"
(let (val

View file

@ -24,6 +24,8 @@
(eval-when-compile
(require 'cl))
(defvar ledger-date-regex "\\([0-9]+\\)[/-]\\([0-9]+\\)[/-]\\([0-9]+\\)")
(defmacro ledger-define-regexp (name regex docs &rest args)
"Simplify the creation of a Ledger regex and helper functions."
(let ((defs

View file

@ -106,7 +106,7 @@ within the transaction."
(extents (ledger-find-xact-extents (point)))
(transaction (buffer-substring (car extents) (cadr extents)))
encoded-date)
(if (string-match "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)" date)
(if (string-match ledger-date-regex date)
(setq encoded-date
(encode-time 0 0 0 (string-to-number (match-string 3 date))
(string-to-number (match-string 2 date))
@ -114,7 +114,7 @@ within the transaction."
(ledger-find-slot encoded-date)
(insert transaction "\n")
(backward-paragraph)
(re-search-forward "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)")
(re-search-forward ledger-date-regex)
(replace-match date)
(re-search-forward "[1-9][0-9]+\.[0-9]+")))