timeclock: print shows timeclock amounts with just 2 decimals, like pre-1.21 (#1527)

This commit is contained in:
Simon Michael 2021-04-12 18:35:39 -10:00
parent 25322e489e
commit f5121129ec
3 changed files with 18 additions and 3 deletions

View File

@ -357,7 +357,7 @@ amountSetFullPrecision a = amountSetPrecision p a
-- Rounding is done with Data.Decimal's default roundTo function:
-- "If the value ends in 5 then it is rounded to the nearest even value (Banker's Rounding)".
-- Does not change the amount's display precision.
-- Intended only for internal use, eg when comparing amounts in tests.
-- Intended mainly for internal use, eg when comparing amounts in tests.
setAmountInternalPrecision :: Word8 -> Amount -> Amount
setAmountInternalPrecision p a@Amount{ aquantity=q, astyle=s } = a{
astyle=s{asprecision=Precision p}
@ -365,7 +365,7 @@ setAmountInternalPrecision p a@Amount{ aquantity=q, astyle=s } = a{
}
-- | Set an amount's internal precision, flipped.
-- Intended only for internal use, eg when comparing amounts in tests.
-- Intended mainly for internal use, eg when comparing amounts in tests.
withInternalPrecision :: Amount -> Word8 -> Amount
withInternalPrecision = flip setAmountInternalPrecision

View File

@ -121,7 +121,11 @@ entryFromTimeclockInOut i o
showtime = take 5 . show
hours = elapsedSeconds (toutc otime) (toutc itime) / 3600 where toutc = localTimeToUTC utc
acctname = tlaccount i
amount = mixedAmount $ hrs hours
-- Generate an hours amount. Unusually, we also round the internal Decimal value,
-- since otherwise it will often have large recurring decimal parts which (since 1.21)
-- print would display all 255 digits of. timeclock amounts have one second resolution,
-- so two decimal places is precise enough (#1527).
amount = mixedAmount $ setAmountInternalPrecision 2 $ hrs hours
ps = [posting{paccount=acctname, pamount=amount, ptype=VirtualPosting, ptransaction=Just t}]

View File

@ -65,6 +65,17 @@ $ hledger -f timeclock:- balance
>2 /line 2: expected timeclock code o/
>= !0
# Timeclock amounts are always rounded to two decimal places,
# even when displayed by print (#1527).
<
i 2020-01-30 08:38:35 a
o 2020-01-30 09:03:35
$ hledger -f timeclock:- print
2020-01-30 * 08:38-09:03
(a) 0.42h
>=
## TODO
## multi-day sessions get a new transaction for each day
#hledger -ftimeclock:- print