hledger/Commands/Print.hs

30 lines
745 B
Haskell
Raw Normal View History

{-# LANGUAGE CPP #-}
{-|
A ledger-compatible @print@ command.
-}
2009-06-02 22:29:01 +04:00
module Commands.Print
where
import Ledger
import Options
#if __GLASGOW_HASKELL__ <= 610
import Prelude hiding ( putStr )
import System.IO.UTF8
#endif
-- | Print ledger transactions in standard format.
2008-10-12 13:17:21 +04:00
print' :: [Opt] -> [String] -> Ledger -> IO ()
print' opts args l = do
t <- getCurrentLocalTime
putStr $ showTransactions (optsToFilterSpec opts args t) l
2008-10-12 13:17:21 +04:00
showTransactions :: FilterSpec -> Ledger -> String
showTransactions filterspec l =
concatMap (showTransactionForPrint effective) $ sortBy (comparing tdate) txns
where
effective = EffectiveDate == whichdate filterspec
txns = jtxns $ filterJournalTransactions filterspec $ journal l