;bin: hledger-dc, hledger-timedothm: dev notes

This commit is contained in:
Simon Michael 2025-09-27 09:51:03 -10:00
parent fb28178e1a
commit 75ce0dde37
2 changed files with 21 additions and 2 deletions

View File

@ -7,6 +7,8 @@
# If it begins with Cr<WHITESPACE> and contains no number, remove that.
# If it begins with Cr<WHITESPACE>, remove that and add a minus sign before the next number, and if that leaves a double minus, cancel those out.
dc2sign() { sed -E -e 's/^(\s+)Dr\s+/\1/i' -e 's/^(\s+)Cr\s+([^0-9]+)$/\1\2/i' -e 's/^(\s+)Cr\s+([^0-9]+)([0-9])/\1\2-\3/i' -e 's/--([0-9])/\1/'; }
# Or with a two space delimiter after Dr/Cr, allowing account names like "Dr Michael:checkup":
#dc2sign() { sed -E -e 's/^(\s+)Dr\s\s+/\1/i' -e 's/^(\s+)Cr\s\s+([^0-9]+)$/\1\2/i' -e 's/^(\s+)Cr\s\s+([^0-9]+)([0-9])/\1\2-\3/i' -e 's/--([0-9])/\1/'; }
dc2sign <"$1" | hledger -f- "${@:2}"
@ -17,14 +19,23 @@ dc2sign <"$1" | hledger -f- "${@:2}"
# 2025-01-01 salary
# Cr revenues 800 USD
# Dr assets
#
# $ hledger -f sample.journaldc print
# 2025-01-01 salary
# Cr revenues 800 USD
# Dr assets
#
# $ hledger dc sample.journaldc print
# 2025-01-01 salary
# revenues -800 USD
# assets
# Dev notes:
# This is syntactic sugar.
# If useful, it should be possible to add this to journal format without too much breakage.
#
# Showing debits/credits separately in output, with a --dc flag, is more work.
# It could be prototyped as a single new report, eg an addon script providing variant of the simple balance report.
# I think both the report calculation and display code would need to change, to sum and show the positive amounts and negative amounts separately.
# It would be a nice feature: offering a more traditional view of things, and reducing sign vs dc doubts.
# Would it provide any real new error checking power ? I'm not sure

View File

@ -26,3 +26,11 @@ hm2dec <"$1" | hledger -f timedot:- "${@:2}" | dec2hm
# (time) 0:30 1:00
# (time) 0:30 1:30
# (time) 0:30 2:00
# Dev notes:
# If useful, there's no reason we couldn't
# 1. add H:M syntax to timedot format
# 2. add a general --hm output flag, affecting display of amounts with
# no commodity,
# or a commodity that looks like a time unit (eg timedot's: s, m, h, d, w, mo, y),
# or a commodity that has a display:time tag.