web: make hledger[-lib] compatible with all of yesod's language extensions
Useful when building all of hledger-web at once.
This commit is contained in:
parent
ef73894889
commit
5b9c5459be
@ -26,7 +26,7 @@ import Hledger.Utils
|
|||||||
instance Show Account where
|
instance Show Account where
|
||||||
show Account{..} = printf "Account %s (boring:%s, ebalance:%s, ibalance:%s)"
|
show Account{..} = printf "Account %s (boring:%s, ebalance:%s, ibalance:%s)"
|
||||||
aname
|
aname
|
||||||
(if aboring then "y" else "n")
|
(if aboring then "y" else "n" :: String)
|
||||||
(showMixedAmount aebalance)
|
(showMixedAmount aebalance)
|
||||||
(showMixedAmount aibalance)
|
(showMixedAmount aibalance)
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ showAccountDebug a = printf "%-25s %4s %4s %s"
|
|||||||
(aname a)
|
(aname a)
|
||||||
(showMixedAmount $ aebalance a)
|
(showMixedAmount $ aebalance a)
|
||||||
(showMixedAmount $ aibalance a)
|
(showMixedAmount $ aibalance a)
|
||||||
(if aboring a then "b" else " ")
|
(if aboring a then "b" else " " :: String)
|
||||||
|
|
||||||
|
|
||||||
tests_Hledger_Data_Account = TestList [
|
tests_Hledger_Data_Account = TestList [
|
||||||
|
|||||||
@ -146,16 +146,18 @@ divideAmount a@Amount{quantity=q} d = a{quantity=q/d}
|
|||||||
isNegativeAmount :: Amount -> Bool
|
isNegativeAmount :: Amount -> Bool
|
||||||
isNegativeAmount Amount{quantity=q} = q < 0
|
isNegativeAmount Amount{quantity=q} = q < 0
|
||||||
|
|
||||||
|
digits = "123456789" :: String
|
||||||
|
|
||||||
-- | Does this amount appear to be zero when displayed with its given precision ?
|
-- | Does this amount appear to be zero when displayed with its given precision ?
|
||||||
isZeroAmount :: Amount -> Bool
|
isZeroAmount :: Amount -> Bool
|
||||||
isZeroAmount a -- a==missingamt = False
|
isZeroAmount a -- a==missingamt = False
|
||||||
| otherwise = (null . filter (`elem` "123456789") . showAmountWithoutPriceOrCommodity) a
|
| otherwise = (null . filter (`elem` digits) . showAmountWithoutPriceOrCommodity) a
|
||||||
|
|
||||||
-- | Is this amount "really" zero, regardless of the display precision ?
|
-- | Is this amount "really" zero, regardless of the display precision ?
|
||||||
-- Since we are using floating point, for now just test to some high precision.
|
-- Since we are using floating point, for now just test to some high precision.
|
||||||
isReallyZeroAmount :: Amount -> Bool
|
isReallyZeroAmount :: Amount -> Bool
|
||||||
isReallyZeroAmount a -- a==missingamt = False
|
isReallyZeroAmount a -- a==missingamt = False
|
||||||
| otherwise = (null . filter (`elem` "123456789") . printf ("%."++show zeroprecision++"f") . quantity) a
|
| otherwise = (null . filter (`elem` digits) . printf ("%."++show zeroprecision++"f") . quantity) a
|
||||||
where zeroprecision = 8
|
where zeroprecision = 8
|
||||||
|
|
||||||
-- | Get the string representation of an amount, based on its commodity's
|
-- | Get the string representation of an amount, based on its commodity's
|
||||||
@ -200,10 +202,10 @@ showAmount a@(Amount (Commodity {symbol=sym,side=side,spaced=spaced}) _ pri) =
|
|||||||
R -> printf "%s%s%s%s" quantity' space sym' price
|
R -> printf "%s%s%s%s" quantity' space sym' price
|
||||||
where
|
where
|
||||||
quantity = showamountquantity a
|
quantity = showamountquantity a
|
||||||
displayingzero = null $ filter (`elem` "123456789") $ quantity
|
displayingzero = null $ filter (`elem` digits) $ quantity
|
||||||
(quantity',sym') | displayingzero = ("0","")
|
(quantity',sym') | displayingzero = ("0","")
|
||||||
| otherwise = (quantity,quoteCommoditySymbolIfNeeded sym)
|
| otherwise = (quantity,quoteCommoditySymbolIfNeeded sym)
|
||||||
space = if (not (null sym') && spaced) then " " else ""
|
space = if (not (null sym') && spaced) then " " else "" :: String
|
||||||
price = maybe "" showPrice pri
|
price = maybe "" showPrice pri
|
||||||
|
|
||||||
-- | Get the string representation of the number part of of an amount,
|
-- | Get the string representation of the number part of of an amount,
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import Hledger.Data.Types
|
|||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
|
|
||||||
|
|
||||||
nonsimplecommoditychars = "0123456789-.@;\n \""
|
nonsimplecommoditychars = "0123456789-.@;\n \"" :: String
|
||||||
|
|
||||||
quoteCommoditySymbolIfNeeded s | any (`elem` nonsimplecommoditychars) s = "\"" ++ s ++ "\""
|
quoteCommoditySymbolIfNeeded s | any (`elem` nonsimplecommoditychars) s = "\"" ++ s ++ "\""
|
||||||
| otherwise = s
|
| otherwise = s
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE NoMonoLocalBinds #-}
|
||||||
{-|
|
{-|
|
||||||
|
|
||||||
Date parsing and utilities for hledger.
|
Date parsing and utilities for hledger.
|
||||||
|
|||||||
@ -340,7 +340,7 @@ nonzerobalanceerror t = printf "could not balance this transaction (%s%s%s)" rms
|
|||||||
| otherwise = "real postings are off by " ++ showMixedAmount (costOfMixedAmount rsum)
|
| otherwise = "real postings are off by " ++ showMixedAmount (costOfMixedAmount rsum)
|
||||||
bvmsg | isReallyZeroMixedAmountCost bvsum = ""
|
bvmsg | isReallyZeroMixedAmountCost bvsum = ""
|
||||||
| otherwise = "balanced virtual postings are off by " ++ showMixedAmount (costOfMixedAmount bvsum)
|
| otherwise = "balanced virtual postings are off by " ++ showMixedAmount (costOfMixedAmount bvsum)
|
||||||
sep = if not (null rmsg) && not (null bvmsg) then "; " else ""
|
sep = if not (null rmsg) && not (null bvmsg) then "; " else "" :: String
|
||||||
|
|
||||||
transactionActualDate :: Transaction -> Day
|
transactionActualDate :: Transaction -> Day
|
||||||
transactionActualDate = tdate
|
transactionActualDate = tdate
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards, NoMonoLocalBinds #-}
|
||||||
{-|
|
{-|
|
||||||
|
|
||||||
A reader for hledger's journal file format
|
A reader for hledger's journal file format
|
||||||
|
|||||||
@ -55,7 +55,7 @@ lowercase = map toLower
|
|||||||
uppercase = map toUpper
|
uppercase = map toUpper
|
||||||
|
|
||||||
strip = lstrip . rstrip
|
strip = lstrip . rstrip
|
||||||
lstrip = dropWhile (`elem` " \t")
|
lstrip = dropWhile (`elem` " \t") :: String -> String
|
||||||
rstrip = reverse . lstrip . reverse
|
rstrip = reverse . lstrip . reverse
|
||||||
|
|
||||||
elideLeft width s =
|
elideLeft width s =
|
||||||
|
|||||||
@ -117,7 +117,7 @@ getPostings st enteredps = do
|
|||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
where Just ps = historicalps
|
where Just ps = historicalps
|
||||||
defaultaccount = maybe Nothing (Just . showacctname) bestmatch
|
defaultaccount = maybe Nothing (Just . showacctname) bestmatch
|
||||||
ordot | null enteredps || length enteredrealps == 1 = ""
|
ordot | null enteredps || length enteredrealps == 1 = "" :: String
|
||||||
| otherwise = ", or . to record"
|
| otherwise = ", or . to record"
|
||||||
account <- runInteraction j $ askFor (printf "account %d%s" n ordot) defaultaccount (Just accept)
|
account <- runInteraction j $ askFor (printf "account %d%s" n ordot) defaultaccount (Just accept)
|
||||||
if account=="."
|
if account=="."
|
||||||
|
|||||||
@ -41,7 +41,7 @@ showLedgerStats l today span =
|
|||||||
w1 = maximum $ map (length . fst) stats
|
w1 = maximum $ map (length . fst) stats
|
||||||
-- w2 = maximum $ map (length . show . snd) stats
|
-- w2 = maximum $ map (length . show . snd) stats
|
||||||
stats = [
|
stats = [
|
||||||
("Main journal file", path) -- ++ " (from " ++ source ++ ")")
|
("Main journal file" :: String, path) -- ++ " (from " ++ source ++ ")")
|
||||||
,("Included journal files", unlines $ reverse $ -- cf journalAddFile
|
,("Included journal files", unlines $ reverse $ -- cf journalAddFile
|
||||||
drop 1 $ journalFilePaths j)
|
drop 1 $ journalFilePaths j)
|
||||||
,("Transactions span", printf "%s to %s (%d days)" (start span) (end span) days)
|
,("Transactions span", printf "%s to %s (%d days)" (start span) (end span) days)
|
||||||
@ -69,7 +69,7 @@ showLedgerStats l today span =
|
|||||||
showelapsed Nothing = ""
|
showelapsed Nothing = ""
|
||||||
showelapsed (Just days) = printf " (%d %s)" days' direction
|
showelapsed (Just days) = printf " (%d %s)" days' direction
|
||||||
where days' = abs days
|
where days' = abs days
|
||||||
direction | days >= 0 = "days ago"
|
direction | days >= 0 = "days ago" :: String
|
||||||
| otherwise = "days from now"
|
| otherwise = "days from now"
|
||||||
tnum = length ts
|
tnum = length ts
|
||||||
start (DateSpan (Just d) _) = show d
|
start (DateSpan (Just d) _) = show d
|
||||||
|
|||||||
@ -55,7 +55,7 @@ binaryfilename progname = prettify $ splitAtElement '.' buildversion
|
|||||||
| patches/="0" = '+' : patches
|
| patches/="0" = '+' : patches
|
||||||
| otherwise = ""
|
| otherwise = ""
|
||||||
(os',suffix)
|
(os',suffix)
|
||||||
| os == "darwin" = ("mac","")
|
| os == "darwin" = ("mac","" :: String)
|
||||||
| os == "mingw32" = ("windows",".exe")
|
| os == "mingw32" = ("windows",".exe")
|
||||||
| otherwise = (os,"")
|
| otherwise = (os,"")
|
||||||
prettify (major:minor:bugfix:[]) = prettify [major,minor,bugfix,"0"]
|
prettify (major:minor:bugfix:[]) = prettify [major,minor,bugfix,"0"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user