diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 9dfeee123..43051fbe5 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -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 diff --git a/hledger-lib/Hledger/Data/Timeclock.hs b/hledger-lib/Hledger/Data/Timeclock.hs index 8e121d6f7..7b67017dd 100644 --- a/hledger-lib/Hledger/Data/Timeclock.hs +++ b/hledger-lib/Hledger/Data/Timeclock.hs @@ -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}] diff --git a/hledger/test/timeclock.test b/hledger/test/timeclock.test index 765a7d9e2..a66557074 100644 --- a/hledger/test/timeclock.test +++ b/hledger/test/timeclock.test @@ -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