time-parsers 0.1.0.0 → 0.1.1.0
raw patch · 4 files changed
+51/−23 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Time.TH: mkDay :: String -> Q Exp
Files
- CHANGELOG.md +2/−0
- src/Data/Time/TH.hs +22/−11
- test/Tests.hs +18/−4
- time-parsers.cabal +9/−8
+ CHANGELOG.md view
@@ -0,0 +1,2 @@+- 0.1.1.0+ - add `mkDay`
src/Data/Time/TH.hs view
@@ -1,9 +1,10 @@ {-# LANGUAGE TemplateHaskell #-} -- | Template Haskell extras for `Data.Time`.-module Data.Time.TH (mkUTCTime) where+module Data.Time.TH (mkUTCTime, mkDay) where +import Data.List (nub) import Data.Time (Day (..), UTCTime (..))-import Data.Time.Parsers (utcTime)+import Data.Time.Parsers (day, utcTime) import Language.Haskell.TH (Exp, Q, integerL, litE, rationalL) import Text.ParserCombinators.ReadP (readP_to_S) @@ -11,13 +12,23 @@ -- -- > t :: UTCTime -- > t = $(mkUTCTime "2014-05-12 00:02:03.456000Z")------ /Since: 0.2.3.0/ mkUTCTime :: String -> Q Exp-mkUTCTime s =- case readP_to_S utcTime s of- [(UTCTime (ModifiedJulianDay d) dt, "")] ->- [| UTCTime (ModifiedJulianDay $(d')) $(dt') :: UTCTime |]- where d' = litE $ integerL d- dt' = litE $ rationalL $ toRational dt- _ -> error $ "Cannot parse date: " ++ s+mkUTCTime s = case nub $ readP_to_S utcTime s of+ [(UTCTime (ModifiedJulianDay d) dt, "")] ->+ [| UTCTime (ModifiedJulianDay $(d')) $(dt') :: UTCTime |]+ where+ d' = litE $ integerL d+ dt' = litE $ rationalL $ toRational dt+ ps -> error $ "Cannot parse date: " ++ s ++ " -- " ++ show ps++-- | Make a 'Day'. Accepts the same strings as `day` parser accepts.+--+-- > d :: Day+-- > d = $(mkDay "2014-05-12")+mkDay :: String -> Q Exp+mkDay s = case nub $ readP_to_S day s of+ [(ModifiedJulianDay d, "")] ->+ [| ModifiedJulianDay $(d') :: Day |]+ where+ d' = litE $ integerL d+ ps -> error $ "Cannot parse day: " ++ s ++ " -- " ++ show ps
test/Tests.hs view
@@ -44,11 +44,25 @@ , "2015-09-07 08:16:40.807 +00:00" , "2015-09-07 11:16:40.807 +03:00" , "2015-09-07 05:16:40.807 -03:00"+ , "2015-09-07 05:16:40.807-03:00"+ , "2015-09-07T05:16:40Z"+ , "2015-09-07 05:16:40Z"+ , "2015-09-07 05:16:40 Z"+ , "2015-09-07 05:16:40+03:00"+ , "2015-09-07 05:16:40 +03:00" ] timeTHTests :: TestTree-timeTHTests =- testCase "time TH example" $ assertBool "should be equal" $ lhs == rhs- where lhs = UTCTime (ModifiedJulianDay 56789) 123.456- rhs = $(mkUTCTime "2014-05-12 00:02:03.456000Z")+timeTHTests = testGroup "TH"+ [ testCase "time" $ assertBool "should be equal" $ lhs0 == rhs0+ , testCase "time' " $ assertBool "should be equal" $ lhs1 == rhs1+ , testCase "day" $ assertBool "should be equal" $ lhs2 == rhs2+ ]+ where+ lhs0 = UTCTime (ModifiedJulianDay 56789) 123.456+ rhs0 = $(mkUTCTime "2014-05-12 00:02:03.456Z")+ lhs1 = UTCTime (ModifiedJulianDay 56789) 123.0+ rhs1 = $(mkUTCTime "2014-05-12 00:02:03Z")+ lhs2 = ModifiedJulianDay 56789+ rhs2 = $(mkDay "2014-05-12")
time-parsers.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.8.0.+-- This file has been generated from package.yaml by hpack version 0.14.0. -- -- see: https://github.com/sol/hpack name: time-parsers-version: 0.1.0.0+version: 0.1.1.0 synopsis: Parsers for types in `time`. description: Parsers for types in `time`. category: Web@@ -13,11 +13,12 @@ maintainer: Oleg Grenrus <oleg.grenrus@iki.fi> license: BSD3 license-file: LICENSE-tested-with: GHC==7.6.3, GHC==7.8.4, GHC==7.10.3+tested-with: GHC==7.6.3, GHC==7.8.4, GHC==7.10.3, GHC==8.0.1 build-type: Simple cabal-version: >= 1.10 extra-source-files:+ CHANGELOG.md README.md source-repository head@@ -29,9 +30,9 @@ src ghc-options: -Wall build-depends:- base >=4.6 && <4.9+ base >=4.6 && <4.10 , parsers >=0.12.2.1 && <0.13- , template-haskell >=2.8.0.0 && <2.11+ , template-haskell >=2.8.0.0 && <2.12 , time >=1.4.2 && <1.7 exposed-modules: Data.Time.Parsers@@ -45,13 +46,13 @@ test ghc-options: -Wall build-depends:- base >=4.6 && <4.9+ base >=4.6 && <4.10 , parsers >=0.12.2.1 && <0.13- , template-haskell >=2.8.0.0 && <2.11+ , template-haskell >=2.8.0.0 && <2.12 , time >=1.4.2 && <1.7 , time-parsers , attoparsec >=0.12.1.6 && <0.14- , bifunctors >=4.2.1 && <5.2+ , bifunctors >=4.2.1 && <5.5 , parsec >=3.1.9 && <3.2 , parsers >=0.12.3 && <0.13 , tasty >=0.10.1.2 && <0.12