use smart dates for -b and -e

This commit is contained in:
Simon Michael 2008-11-22 12:37:55 +00:00
parent 7362fbd730
commit fcdc4dc273
3 changed files with 14 additions and 14 deletions

3
NOTES
View File

@ -13,7 +13,8 @@ implementations were its consequences." --Niklaus Wirth
*** display mixed amounts vertically, not horizontally
** features
*** flexible date expressions, for easier time reports
**** use Dates for -b/-e
**** more formats
**** periods
*** commodity @ rate, for tracking client hours in main ledger
*** actual/effective entry & txn dates, for ?
*** --display, for reconciling recent transactions with real balance

View File

@ -5,6 +5,8 @@ import System.Console.GetOpt
import System.Directory
import Text.Printf
import Ledger.AccountName (negativepatternchar)
import Ledger.Parse (smartparsedate)
import Ledger.Dates
usagehdr = "Usage: hledger [OPTS] balance|print|register [ACCTPATS] [-- DESCPATS]\n\nOptions"++warning++":"
warning = if negativepatternchar=='-' then " (must appear before command)" else " (can appear anywhere)"
@ -87,24 +89,24 @@ tildeExpand ('~':'/':xs) = getHomeDirectory >>= return . (++ ('/':xs))
-- return (homeDirectory pw ++ path)
tildeExpand xs = return xs
-- | get the value of the begin date option, or a default
beginDateFromOpts :: [Opt] -> String
-- | Get the value of the begin date option, if any.
beginDateFromOpts :: [Opt] -> Maybe Date
beginDateFromOpts opts =
case beginopts of
(x:_) -> last beginopts
_ -> defaultdate
(x:_) -> Just $ smartparsedate $ last beginopts
_ -> Nothing
where
beginopts = concatMap getbegindate opts
getbegindate (Begin s) = [s]
getbegindate _ = []
defaultdate = ""
-- | get the value of the end date option, or a default
endDateFromOpts :: [Opt] -> String
-- | Get the value of the end date option, if any.
endDateFromOpts :: [Opt] -> Maybe Date
endDateFromOpts opts =
case endopts of
(x:_) -> last endopts
_ -> defaultdate
(x:_) -> Just $ smartparsedate $ last endopts
_ -> Nothing
where
endopts = concatMap getenddate opts
getenddate (End s) = [s]

View File

@ -64,9 +64,6 @@ main = do
| cmd `isPrefixOf` "test" = runtests args >> return ()
| otherwise = putStr usage
parsemaybedate "" = Nothing
parsemaybedate s = Just (parsedate s)
-- | parse the user's specified ledger file and do some action with it
-- (or report a parse error). This function makes the whole thing go.
parseLedgerAndDo :: [Opt] -> [String] -> ([Opt] -> [String] -> Ledger -> IO ()) -> IO ()
@ -74,8 +71,8 @@ parseLedgerAndDo opts args cmd =
ledgerFilePathFromOpts opts >>= parseLedgerFile >>= either printParseError runcmd
where
runcmd = cmd opts args . cacheLedger apats . canonicaliseAmounts . filterRawLedger b e dpats c r
b = parsemaybedate (beginDateFromOpts opts)
e = parsemaybedate (endDateFromOpts opts)
b = beginDateFromOpts opts
e = endDateFromOpts opts
(apats,dpats) = parseAccountDescriptionArgs args
c = Cleared `elem` opts
r = Real `elem` opts