begin cleaning up Dates api, move firstJust

This commit is contained in:
Simon Michael 2012-04-16 16:44:41 +00:00
parent 56cf9b21cb
commit 68966fe43b
2 changed files with 32 additions and 5 deletions

View File

@ -20,7 +20,33 @@ quarterly, etc.
-- XXX fromGregorian silently clips bad dates, use fromGregorianValid instead ?
module Hledger.Data.Dates
module Hledger.Data.Dates (
-- * Misc date handling utilities
getCurrentDay,
getCurrentMonth,
getCurrentYear,
nulldate,
spanContainsDate,
parsedate,
showDate,
elapsedSeconds,
prevday,
parsePeriodExpr,
nulldatespan,
tests_Hledger_Data_Dates,
failIfInvalidYear,
datesepchar,
datesepchars,
spanIntersect,
orDatesFrom,
smartdate,
splitSpan,
fixSmartDate,
fixSmartDateStr,
fixSmartDateStrEither',
daysInSpan,
maybePeriod,
)
where
import Control.Monad
@ -280,10 +306,6 @@ nthdayofweekcontaining n d | d1 >= d = d1
----------------------------------------------------------------------
-- parsing
firstJust ms = case dropWhile (==Nothing) ms of
[] -> Nothing
(md:_) -> md
-- | Parse a couple of date-time string formats to a time type.
parsedatetimeM :: String -> Maybe LocalTime
parsedatetimeM s = firstJust [

View File

@ -404,3 +404,8 @@ expandPath pos fp = liftM mkAbsolute (expandHome fp)
expandHome inname | "~/" `isPrefixOf` inname = do homedir <- liftIO getHomeDirectory
return $ homedir ++ drop 1 inname
| otherwise = return inname
firstJust ms = case dropWhile (==Nothing) ms of
[] -> Nothing
(md:_) -> md