stats: better output when last transaction is in the future

This commit is contained in:
Simon Michael 2010-02-27 20:09:20 +00:00
parent bd3148c690
commit cc8f4926cf

View File

@ -32,8 +32,7 @@ showStats _ _ l today =
stats = [ stats = [
("File", filepath $ journal l) ("File", filepath $ journal l)
,("Period", printf "%s to %s (%d days)" (start span) (end span) days) ,("Period", printf "%s to %s (%d days)" (start span) (end span) days)
,("Last transaction", maybe "none" show lastdate ++ ,("Last transaction", maybe "none" show lastdate ++ showelapsed lastelapsed)
maybe "" (printf " (%d days ago)") lastelapsed)
,("Transactions", printf "%d (%0.1f per day)" tnum txnrate) ,("Transactions", printf "%d (%0.1f per day)" tnum txnrate)
,("Transactions last 30 days", printf "%d (%0.1f per day)" tnum30 txnrate30) ,("Transactions last 30 days", printf "%d (%0.1f per day)" tnum30 txnrate30)
,("Transactions last 7 days", printf "%d (%0.1f per day)" tnum7 txnrate7) ,("Transactions last 7 days", printf "%d (%0.1f per day)" tnum7 txnrate7)
@ -50,6 +49,11 @@ showStats _ _ l today =
lastdate | null ts = Nothing lastdate | null ts = Nothing
| otherwise = Just $ tdate $ last ts | otherwise = Just $ tdate $ last ts
lastelapsed = maybe Nothing (Just . diffDays today) lastdate lastelapsed = maybe Nothing (Just . diffDays today) lastdate
showelapsed Nothing = ""
showelapsed (Just days) = printf " (%d %s)" days' direction
where days' = abs days
direction | days >= 0 = "days ago"
| otherwise = "days from now"
tnum = length ts tnum = length ts
span = rawdatespan l span = rawdatespan l
start (DateSpan (Just d) _) = show d start (DateSpan (Just d) _) = show d