diff --git a/NOTES b/NOTES index 88e4c67f9..7473fa60b 100644 --- a/NOTES +++ b/NOTES @@ -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 diff --git a/Options.hs b/Options.hs index d1f3bb0c1..047e8c2f6 100644 --- a/Options.hs +++ b/Options.hs @@ -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] diff --git a/hledger.hs b/hledger.hs index 020b249f5..ad884eca6 100644 --- a/hledger.hs +++ b/hledger.hs @@ -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