mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-07 21:15:19 +03:00
fix:timedot: parse unitful quantities more accurately (fix #2096)
A quantity with a unit like "15m" was being parsed internally as 0.249999999... rather than 0.25 (and since hledger 1.21, printed that way also). Now we round such quantities to two places during parsing, to get exact quarter-hour amounts.
This commit is contained in:
parent
ffc535ad64
commit
9ead8a64e1
@ -52,6 +52,7 @@ import Text.Megaparsec.Char
|
||||
import Hledger.Data
|
||||
import Hledger.Read.Common hiding (emptyorcommentlinep)
|
||||
import Hledger.Utils
|
||||
import Data.Decimal (roundTo)
|
||||
|
||||
--- ** doctest setup
|
||||
-- $setup
|
||||
@ -228,7 +229,7 @@ numericquantityp = do
|
||||
let q' =
|
||||
case msymbol of
|
||||
Nothing -> q
|
||||
Just sym ->
|
||||
Just sym -> roundTo 2 $
|
||||
case lookup sym timeUnits of
|
||||
Just mult -> q * mult
|
||||
Nothing -> q -- shouldn't happen.. ignore
|
||||
|
@ -42,3 +42,18 @@ $ hledger -ftimedot:- reg
|
||||
# 3. Tags are recognised. Account aliases are applied.
|
||||
$ hledger -ftimedot:- reg tag:posting-tag --alias fos:haskell=λ
|
||||
2023-01-01 different transac.. (λ) 1.00 1.00
|
||||
|
||||
# 4. Each of these formats is printed as exactly a quarter hour.
|
||||
<
|
||||
2023-01-01
|
||||
a .
|
||||
b 0.25
|
||||
c 15m
|
||||
|
||||
$ hledger -ftimedot:- print
|
||||
2023-01-01 *
|
||||
(a) 0.25
|
||||
(b) 0.25
|
||||
(c) 0.25
|
||||
|
||||
>=
|
||||
|
Loading…
Reference in New Issue
Block a user