when options are repeated, use the last instead of the first

This commit is contained in:
Simon Michael 2008-12-04 20:11:35 +00:00
parent f794445451
commit eacea41dac

View File

@ -129,46 +129,46 @@ fixOptDates opts = do
-- others are ignored. -- others are ignored.
dateSpanFromOpts :: Day -> [Opt] -> DateSpan dateSpanFromOpts :: Day -> [Opt] -> DateSpan
dateSpanFromOpts refdate opts dateSpanFromOpts refdate opts
| not $ null popts = snd $ parsePeriodExpr refdate $ head popts | not $ null popts = snd $ parsePeriodExpr refdate $ last popts
| otherwise = DateSpan firstb firste | otherwise = DateSpan lastb laste
where where
popts = optValuesForConstructor Period opts popts = optValuesForConstructor Period opts
bopts = optValuesForConstructor Begin opts bopts = optValuesForConstructor Begin opts
eopts = optValuesForConstructor End opts eopts = optValuesForConstructor End opts
firstb = listtomaybeday bopts lastb = listtomaybeday bopts
firste = listtomaybeday eopts laste = listtomaybeday eopts
listtomaybeday vs = if null vs then Nothing else Just $ parse $ head vs listtomaybeday vs = if null vs then Nothing else Just $ parse $ last vs
where parse = parsedate . fixSmartDateStr refdate where parse = parsedate . fixSmartDateStr refdate
-- | Figure out the reporting interval, if any, specified by the options. -- | Figure out the reporting interval, if any, specified by the options.
-- If there is a period option, the others are ignored. -- If there is a period option, the others are ignored.
intervalFromOpts :: [Opt] -> Interval intervalFromOpts :: [Opt] -> Interval
intervalFromOpts opts intervalFromOpts opts
| not $ null popts = fst $ parsePeriodExpr refdate $ head popts | not $ null popts = fst $ parsePeriodExpr refdate $ last popts
| otherwise = case otheropts of | null otheropts = NoInterval
[] -> NoInterval | otherwise = case last otheropts of
(WeeklyOpt:_) -> Weekly WeeklyOpt -> Weekly
(MonthlyOpt:_) -> Monthly MonthlyOpt -> Monthly
(YearlyOpt:_) -> Yearly YearlyOpt -> Yearly
where where
popts = optValuesForConstructor Period opts popts = optValuesForConstructor Period opts
otheropts = filter (`elem` [WeeklyOpt,MonthlyOpt,YearlyOpt]) opts otheropts = filter (`elem` [WeeklyOpt,MonthlyOpt,YearlyOpt]) opts
-- doesn't affect the interval, but parsePeriodExpr needs something -- doesn't affect the interval, but parsePeriodExpr needs something
refdate = parsedate "0001/01/01" refdate = parsedate "0001/01/01"
-- | Get the value of the (first) depth option, if any. -- | Get the value of the (last) depth option, if any.
depthFromOpts :: [Opt] -> Maybe Int depthFromOpts :: [Opt] -> Maybe Int
depthFromOpts opts = listtomaybeint $ optValuesForConstructor Depth opts depthFromOpts opts = listtomaybeint $ optValuesForConstructor Depth opts
where where
listtomaybeint [] = Nothing listtomaybeint [] = Nothing
listtomaybeint vs = Just $ read $ head vs listtomaybeint vs = Just $ read $ last vs
-- | Get the value of the (first) display option, if any. -- | Get the value of the (last) display option, if any.
displayFromOpts :: [Opt] -> Maybe String displayFromOpts :: [Opt] -> Maybe String
displayFromOpts opts = listtomaybe $ optValuesForConstructor Display opts displayFromOpts opts = listtomaybe $ optValuesForConstructor Display opts
where where
listtomaybe [] = Nothing listtomaybe [] = Nothing
listtomaybe vs = Just $ head vs listtomaybe vs = Just $ last vs
-- | Get the ledger file path from options, an environment variable, or a default -- | Get the ledger file path from options, an environment variable, or a default
ledgerFilePathFromOpts :: [Opt] -> IO String ledgerFilePathFromOpts :: [Opt] -> IO String