lib: Hledger.Data.Dates: parsedateM -> parsedate
M makes me think of monad and is awkward to type for this common helper; Maybe is expected for a parser.
This commit is contained in:
parent
2288f5193d
commit
b7509030c5
@ -38,7 +38,7 @@ module Hledger.Data.Dates (
|
|||||||
nulldate,
|
nulldate,
|
||||||
spanContainsDate,
|
spanContainsDate,
|
||||||
periodContainsDate,
|
periodContainsDate,
|
||||||
parsedateM,
|
parsedate,
|
||||||
showDate,
|
showDate,
|
||||||
showEFDate,
|
showEFDate,
|
||||||
showDateSpan,
|
showDateSpan,
|
||||||
@ -778,8 +778,8 @@ advanceToNthWeekday n wd s =
|
|||||||
-- parsing
|
-- parsing
|
||||||
|
|
||||||
-- -- | Parse a couple of date-time string formats to a time type.
|
-- -- | Parse a couple of date-time string formats to a time type.
|
||||||
-- parsedatetimeM :: String -> Maybe LocalTime
|
-- parsedatetime :: String -> Maybe LocalTime
|
||||||
-- parsedatetimeM s = asum [
|
-- parsedatetime s = asum [
|
||||||
-- parseTimeM TruedefaultTimeLocale "%Y/%m/%d %H:%M:%S" s,
|
-- parseTimeM TruedefaultTimeLocale "%Y/%m/%d %H:%M:%S" s,
|
||||||
-- parseTimeM TruedefaultTimeLocale "%Y-%m-%d %H:%M:%S" s
|
-- parseTimeM TruedefaultTimeLocale "%Y-%m-%d %H:%M:%S" s
|
||||||
-- ]
|
-- ]
|
||||||
@ -787,14 +787,14 @@ advanceToNthWeekday n wd s =
|
|||||||
-- | Try to parse a couple of date string formats:
|
-- | Try to parse a couple of date string formats:
|
||||||
-- `YYYY-MM-DD`, `YYYY/MM/DD` or `YYYY.MM.DD`, with leading zeros required.
|
-- `YYYY-MM-DD`, `YYYY/MM/DD` or `YYYY.MM.DD`, with leading zeros required.
|
||||||
-- For internal use, not quite the same as the journal's "simple dates".
|
-- For internal use, not quite the same as the journal's "simple dates".
|
||||||
-- >>> parsedateM "2008/02/03"
|
-- >>> parsedate "2008/02/03"
|
||||||
-- Just 2008-02-03
|
-- Just 2008-02-03
|
||||||
-- >>> parsedateM "2008/02/03/"
|
-- >>> parsedate "2008/02/03/"
|
||||||
-- Nothing
|
-- Nothing
|
||||||
-- >>> parsedateM "2008/02/30"
|
-- >>> parsedate "2008/02/30"
|
||||||
-- Nothing
|
-- Nothing
|
||||||
parsedateM :: String -> Maybe Day
|
parsedate :: String -> Maybe Day
|
||||||
parsedateM s = asum [
|
parsedate s = asum [
|
||||||
parseTimeM True defaultTimeLocale "%Y-%m-%d" s,
|
parseTimeM True defaultTimeLocale "%Y-%m-%d" s,
|
||||||
parseTimeM True defaultTimeLocale "%Y/%m/%d" s,
|
parseTimeM True defaultTimeLocale "%Y/%m/%d" s,
|
||||||
parseTimeM True defaultTimeLocale "%Y.%m.%d" s
|
parseTimeM True defaultTimeLocale "%Y.%m.%d" s
|
||||||
|
|||||||
@ -151,7 +151,7 @@ import System.FilePath ((<.>), (</>), splitDirectories, splitFileName, takeFileN
|
|||||||
import System.Info (os)
|
import System.Info (os)
|
||||||
import System.IO (Handle, hPutStrLn, stderr)
|
import System.IO (Handle, hPutStrLn, stderr)
|
||||||
|
|
||||||
import Hledger.Data.Dates (getCurrentDay, parsedateM, showDate)
|
import Hledger.Data.Dates (getCurrentDay, parsedate, showDate)
|
||||||
import Hledger.Data.Types
|
import Hledger.Data.Types
|
||||||
import Hledger.Read.Common
|
import Hledger.Read.Common
|
||||||
import Hledger.Read.InputOptions
|
import Hledger.Read.InputOptions
|
||||||
@ -419,7 +419,7 @@ previousLatestDates f = do
|
|||||||
let nls = zip [1::Int ..] $ T.lines t
|
let nls = zip [1::Int ..] $ T.lines t
|
||||||
fmap catMaybes $ forM nls $ \(n,l) -> do
|
fmap catMaybes $ forM nls $ \(n,l) -> do
|
||||||
let s = T.unpack $ T.strip l
|
let s = T.unpack $ T.strip l
|
||||||
case (s, parsedateM s) of
|
case (s, parsedate s) of
|
||||||
("", _) -> return Nothing
|
("", _) -> return Nothing
|
||||||
(_, Nothing) -> error' (printf "%s:%d: invalid date: \"%s\"" latestfile n s)
|
(_, Nothing) -> error' (printf "%s:%d: invalid date: \"%s\"" latestfile n s)
|
||||||
(_, Just d) -> return $ Just d
|
(_, Just d) -> return $ Just d
|
||||||
|
|||||||
@ -516,7 +516,7 @@ valuationTypeFromRawOpts rawopts = case (balancecalcopt rawopts, directval) of
|
|||||||
| t `elem` ["then" ,"t"] = Just $ AtThen mc
|
| t `elem` ["then" ,"t"] = Just $ AtThen mc
|
||||||
| t `elem` ["end" ,"e"] = Just $ AtEnd mc
|
| t `elem` ["end" ,"e"] = Just $ AtEnd mc
|
||||||
| t `elem` ["now" ,"n"] = Just $ AtNow mc
|
| t `elem` ["now" ,"n"] = Just $ AtNow mc
|
||||||
| otherwise = case parsedateM t of
|
| otherwise = case parsedate t of
|
||||||
Just d -> Just $ AtDate d mc
|
Just d -> Just $ AtDate d mc
|
||||||
Nothing -> usageError $ "could not parse \""++t++"\" as valuation type, should be: then|end|now|t|e|n|YYYY-MM-DD"
|
Nothing -> usageError $ "could not parse \""++t++"\" as valuation type, should be: then|end|now|t|e|n|YYYY-MM-DD"
|
||||||
where
|
where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user