WIP: hour precision.

This commit is contained in:
David Keegan 2013-10-28 11:29:34 +00:00
parent db568429e2
commit a894537691
3 changed files with 24 additions and 13 deletions

View file

@ -1,6 +1,7 @@
An add-on to ledger-mode which appends recurring transactions to
the current ledger file. Recurring transactions are configured in a
separate file which conforms to ledger file format and resides in
the same directory as the ledger file.
the current ledger file, usually on entry to ledger-mode. Recurring
transactions are configured in a separate file which conforms to
ledger file format and resides in the same directory as the ledger
file.

View file

@ -12,6 +12,9 @@ ReDate = '\d{4}%s\d{1,2}%s\d{1,2}' % (ReDateSep, ReDateSep)
RePeriod = '(\d+)([ymwd])'
DateFormat = '%Y-%m-%d'
DateFormatH = DateFormat + ' %H';
DateFormatHm = DateFormatH + ':%M';
DateFormatHms = DateFormatHm + ':%S';
SecPerDay = 24 * 60 * 60
@ -19,7 +22,11 @@ def _Throw(Msg): Misc.Throw(Msg, ModuleName)
def DateParse(Datestr):
"""Converts a date string to seconds since the epoch."""
return mktime(strptime(Datestr, DateFormat))
Fs = DateFormat;
if length(Datestr) > 16 : Fs = DateFormatHms;
elif length(Datestr) > 13 : Fs = DateFormatHm;
elif length(Datestr) > 10 : Fs = DateFormatH;
return mktime(strptime(Datestr, Fs))
def DateToText(Seconds):
# Round seconds to integer first as we're truncating the time

View file

@ -11,9 +11,10 @@
;;; Commentary:
;; An add-on to ledger-mode which appends recurring transactions to
;; the current ledger file. Recurring transactions are configured in a
;; separate file which conforms to ledger file format and resides in
;; the same directory as the ledger file.
;; the current ledger file, usually on entry to ledger-mode. Recurring
;; transactions are configured in a separate file which conforms to
;; ledger file format and resides in the same directory as the ledger
;; file.
;;; Code:
@ -22,7 +23,7 @@
;;;###autoload
(defgroup dklrt nil
"Customisation of dklrt package (Ledger Recurring Transactions)."
"Package dklrt (Ledger Recurring Transactions)."
:tag "dklrt"
:group 'dk)
@ -41,7 +42,7 @@ The default assumes python is on the PATH."
:tag "dklrt-PythonProgram"
:type '(string))
(defcustom dklrt-AppendBefore "1w"
(defcustom dklrt-AppendBefore "3d"
"Controls when a recurring transaction is actually appended.
The value is a period do list format: <integer><y|m|d|w|h>. A
recurring transaction is appended when the current date/time is
@ -69,7 +70,7 @@ transaction date."
; Hard-coded alternative value for debug only.
(or dklrt-PackageDirectory
(setq dklrt-PackageDirectory "/opt/dk/emacs/dklrt-20131028.954/"))
(setq dklrt-PackageDirectory "/opt/dk/emacs/dklrt-20131028.1025/"))
;;;###autoload
(defun dklrt-SetCcKeys()
@ -94,9 +95,11 @@ To invoke, add this function to `ledger-mode-hook'."
((Lfn (buffer-file-name))
(Cfn (dklrt-RecurringConfigFileName Lfn))
(Pfn (expand-file-name "Recurring.py" dklrt-PackageDirectory))
(Td (dkmisc-TimeApplyShift (dkmisc-DateToText)
(or dklrt-AppendBefore "0h")))
(Sc (format "%s %s %s %s %s" dklrt-PythonProgram Pfn Lfn Td Cfn)))
(AppendBefore
(if (> (length dklrt-AppendBefore) 0) dklrt-AppendBefore "0h"))
(Td (dkmisc-TimeApplyShift (dkmisc-DateToText) AppendBefore))
(Sc (format "\"%s\" \"%s\" \"%s\" \"%s\" \"%s\""
dklrt-PythonProgram Pfn Lfn Td Cfn)))
(message "Invoking: \"%s\"..." Sc)
(let*