time-parsers 0.1.2.1 → 0.2
raw patch · 5 files changed
+49/−14 lines, 5 filesdep ~basedep ~bifunctorsdep ~template-haskellPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, bifunctors, template-haskell
API changes (from Hackage documentation)
+ Data.Time.Parsers: year :: DateParsing m => m Integer
Files
- CHANGELOG.md +4/−0
- src/Data/Time/Parsers.hs +15/−3
- src/Data/Time/TH.hs +8/−3
- test/Tests.hs +2/−0
- time-parsers.cabal +20/−8
CHANGELOG.md view
@@ -1,3 +1,7 @@+- 0.2+ - Add `year` parser which requires at least four digits.+ Use it in `month`, `day` etc.+ - 0.1.2.1 - Use `unexpected` instead of `fail`
src/Data/Time/Parsers.hs view
@@ -14,6 +14,7 @@ module Data.Time.Parsers ( day , month+ , year , localTime , timeOfDay , timeZone@@ -48,14 +49,25 @@ toPico :: Integer -> Pico toPico = unsafeCoerce +-- | Parse a year @YYYY@, with at least 4 digits. Does not include any sign.+--+-- @since 0.2+year :: DateParsing m => m Integer+year = do+ ds <- some digit+ if length ds < 4+ then unexpected "expected year with at least 4 digits"+ else return (foldl' step 0 ds)+ where step a w = a * 10 + fromIntegral (ord w - 48)+ -- | Parse a month of the form @YYYY-MM@ month :: DateParsing m => m (Integer, Int) month = do s <- negate <$ char '-' <|> id <$ char '+' <|> return id- y <- decimal+ y <- year _ <- char '-' m <- twoDigits- if (1 <= m && m <= 12)+ if 1 <= m && m <= 12 then return (s y, m) else unexpected "Invalid month" {-# INLINE month #-}@@ -64,7 +76,7 @@ day :: DateParsing m => m Day day = do s <- negate <$ char '-' <|> id <$ char '+' <|> return id- y <- decimal+ y <- year _ <- char '-' m <- twoDigits _ <- char '-'
src/Data/Time/TH.hs view
@@ -1,11 +1,16 @@+{-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >= 800+{-# LANGUAGE TemplateHaskellQuotes #-}+#else {-# LANGUAGE TemplateHaskell #-}+#endif -- | Template Haskell extras for `Data.Time`. module Data.Time.TH (mkUTCTime, mkDay) where import Data.List (nub) import Data.Time (Day (..), UTCTime (..)) import Data.Time.Parsers (day, utcTime)-import Language.Haskell.TH (Exp, Q, integerL, litE, rationalL)+import Language.Haskell.TH (Exp, Q, integerL, litE, appE, sigE, rationalL) import Text.ParserCombinators.ReadP (readP_to_S) -- | Make a 'UTCTime'. Accepts the same strings as `utcTime` parser accepts.@@ -15,7 +20,7 @@ mkUTCTime :: String -> Q Exp mkUTCTime s = case nub $ readP_to_S utcTime s of [(UTCTime (ModifiedJulianDay d) dt, "")] ->- [| UTCTime (ModifiedJulianDay $(d')) $(dt') :: UTCTime |]+ ([| UTCTime |] `appE` ([| ModifiedJulianDay |] `appE` d') `appE` dt') `sigE` [t| UTCTime |] where d' = litE $ integerL d dt' = litE $ rationalL $ toRational dt@@ -28,7 +33,7 @@ mkDay :: String -> Q Exp mkDay s = case nub $ readP_to_S day s of [(ModifiedJulianDay d, "")] ->- [| ModifiedJulianDay $(d') :: Day |]+ ([| ModifiedJulianDay |] `appE` d') `sigE` [t| Day |] where d' = litE $ integerL d ps -> error $ "Cannot parse day: " ++ s ++ " -- " ++ show ps
test/Tests.hs view
@@ -72,6 +72,7 @@ , "2015-09-07 05:16:40 Z" , "2015-09-07 05:16:40+03:00" , "2015-09-07 05:16:40 +03:00"+ , "0000-09-07 05:16:40 +03:00" ] monthStrings :: [String]@@ -85,6 +86,7 @@ [ "2016-13" , "2016-00" , "2016-1"+ , "216-01" ] timeTHTests :: TestTree
time-parsers.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: time-parsers-version: 0.1.2.1+version: 0.2 synopsis: Parsers for types in `time`. category: Parsing description:@@ -17,7 +17,19 @@ license: BSD3 license-file: LICENSE tested-with:- GHC ==8.8.1 || ==8.6.5 || ==8.4.4 || ==8.2.2 || ==8.0.2 || ==7.10.3 || ==7.8.4 || ==7.6.3+ GHC ==7.6.3+ || ==7.8.4+ || ==7.10.3+ || ==8.0.2+ || ==8.2.2+ || ==8.4.4+ || ==8.6.5+ || ==8.8.4+ || ==8.10.7+ || ==9.0.2+ || ==9.2.7+ || ==9.4.4+ || ==9.6.1 build-type: Simple extra-source-files:@@ -32,10 +44,10 @@ hs-source-dirs: src ghc-options: -Wall build-depends:- base >=4.6 && <4.13+ base >=4.6 && <4.19 , parsers >=0.12.2.1 && <0.13- , template-haskell >=2.8.0.0 && <2.15- , time >=1.4.0.1 && <1.9+ , template-haskell >=2.8.0.0 && <2.21+ , time >=1.4.0.1 && <1.13 exposed-modules: Data.Time.Parsers@@ -49,12 +61,12 @@ hs-source-dirs: test ghc-options: -Wall build-depends:- attoparsec >=0.12.1.6 && <0.14+ attoparsec >=0.12.1.6 && <0.15 , base- , bifunctors >=4.2.1 && <5.6+ , bifunctors >=4.2.1 && <5.7 , parsec >=3.1.9 && <3.2 , parsers >=0.12.3 && <0.13- , tasty >=0.10.1.2 && <1.3+ , tasty >=0.10.1.2 && <1.5 , tasty-hunit >=0.9.2 && <0.11 , template-haskell , text