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:
Simon Michael 2025-04-22 10:40:41 -10:00
parent 2288f5193d
commit b7509030c5
3 changed files with 11 additions and 11 deletions

View File

@ -38,7 +38,7 @@ module Hledger.Data.Dates (
nulldate,
spanContainsDate,
periodContainsDate,
parsedateM,
parsedate,
showDate,
showEFDate,
showDateSpan,
@ -778,8 +778,8 @@ advanceToNthWeekday n wd s =
-- parsing
-- -- | Parse a couple of date-time string formats to a time type.
-- parsedatetimeM :: String -> Maybe LocalTime
-- parsedatetimeM s = asum [
-- parsedatetime :: String -> Maybe LocalTime
-- parsedatetime s = asum [
-- 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:
-- `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".
-- >>> parsedateM "2008/02/03"
-- >>> parsedate "2008/02/03"
-- Just 2008-02-03
-- >>> parsedateM "2008/02/03/"
-- >>> parsedate "2008/02/03/"
-- Nothing
-- >>> parsedateM "2008/02/30"
-- >>> parsedate "2008/02/30"
-- Nothing
parsedateM :: String -> Maybe Day
parsedateM s = asum [
parsedate :: String -> Maybe Day
parsedate s = asum [
parseTimeM True defaultTimeLocale "%Y-%m-%d" s,
parseTimeM True defaultTimeLocale "%Y/%m/%d" s,
parseTimeM True defaultTimeLocale "%Y.%m.%d" s

View File

@ -151,7 +151,7 @@ import System.FilePath ((<.>), (</>), splitDirectories, splitFileName, takeFileN
import System.Info (os)
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.Read.Common
import Hledger.Read.InputOptions
@ -419,7 +419,7 @@ previousLatestDates f = do
let nls = zip [1::Int ..] $ T.lines t
fmap catMaybes $ forM nls $ \(n,l) -> do
let s = T.unpack $ T.strip l
case (s, parsedateM s) of
case (s, parsedate s) of
("", _) -> return Nothing
(_, Nothing) -> error' (printf "%s:%d: invalid date: \"%s\"" latestfile n s)
(_, Just d) -> return $ Just d

View File

@ -516,7 +516,7 @@ valuationTypeFromRawOpts rawopts = case (balancecalcopt rawopts, directval) of
| t `elem` ["then" ,"t"] = Just $ AtThen mc
| t `elem` ["end" ,"e"] = Just $ AtEnd mc
| t `elem` ["now" ,"n"] = Just $ AtNow mc
| otherwise = case parsedateM t of
| otherwise = case parsedate t of
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"
where