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 *** display mixed amounts vertically, not horizontally
** features ** features
*** flexible date expressions, for easier time reports *** flexible date expressions, for easier time reports
**** use Dates for -b/-e **** more formats
**** periods
*** commodity @ rate, for tracking client hours in main ledger *** commodity @ rate, for tracking client hours in main ledger
*** actual/effective entry & txn dates, for ? *** actual/effective entry & txn dates, for ?
*** --display, for reconciling recent transactions with real balance *** --display, for reconciling recent transactions with real balance

View File

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

View File

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