dates 0.2.3.0 → 0.2.3.1
raw patch · 2 files changed
+41/−8 lines, 2 filesdep +template-haskelldep ~basedep ~timePVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies added: template-haskell
Dependency ranges changed: base, time
API changes (from Hackage documentation)
+ Data.Dates.Formats: df :: QuasiQuoter
Files
- Data/Dates/Formats.hs +31/−2
- dates.cabal +10/−6
Data/Dates/Formats.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE UnicodeSyntax, DeriveDataTypeable, FlexibleContexts, FlexibleInstances #-}+{-# LANGUAGE UnicodeSyntax, DeriveDataTypeable, FlexibleContexts, FlexibleInstances, LambdaCase, BlockArguments, QuasiQuotes, TemplateHaskell #-} -- | This module allows to parse arbitrary date formats. -- Date formats are specified as strings: --@@ -16,12 +16,15 @@ (FormatElement (..), Format, FormatParser, parseFormat, pFormat, formatParser,- parseDateFormat+ parseDateFormat,+ df ) where import Control.Applicative ((<$>)) import Data.Monoid import Text.Parsec+import Language.Haskell.TH+import Language.Haskell.TH.Quote (QuasiQuoter(..)) import Data.Dates.Types import Data.Dates.Internal (number)@@ -142,4 +145,30 @@ parseDateFormat formatStr str = do format <- parseFormat formatStr runParser (formatParser format) () "(date)" str++df :: QuasiQuoter+df = QuasiQuoter+ { quoteExp = either (fail . show) (listE . fmap fe2th) . parseFormat+ , quotePat = err+ , quoteType = err+ , quoteDec = err+ }+ where+ fe2th :: FormatElement -> ExpQ+ fe2th = \case+ YEAR x y -> [e|YEAR $(b x) $(i y) |]+ MONTH x y -> [e|MONTH $(b x) $(i y) |]+ DAY x y -> [e|DAY $(b x) $(i y) |]+ HOUR x y -> [e|HOUR $(b x) $(i y) |]+ MINUTE x y -> [e|MINUTE $(b x) $(i y) |]+ SECOND x y -> [e|SECOND $(b x) $(i y) |]+ Whitespace x -> [e|Whitespace $(b x) |]+ Fixed x y -> [e|Fixed $(b x) $(stringE y)|]+ err = const $ fail "Date format parser only defined for Exp"+ b :: Bool -> ExpQ+ b = conE . \case+ True -> 'True+ False -> 'False+ i :: Int -> ExpQ+ i = litE . integerL . toInteger
dates.cabal view
@@ -1,5 +1,5 @@ name: dates-version: 0.2.3.0+version: 0.2.3.1 synopsis: Small library for parsing different dates formats. description: This package allows to parse many different formats of dates. Both absolute and relative dates are supported.@@ -33,7 +33,7 @@ -- copyright: category: Data build-type: Simple-cabal-version: >=1.8+cabal-version: >=1.10 library exposed-modules: Data.Dates,@@ -41,22 +41,26 @@ Data.Dates.Formats, Data.Dates.Internal - build-depends: base >=4.9 && < 4.13,+ build-depends: base >=4.9 && < 4.16, base-unicode-symbols ==0.2.*,- time >= 1.4 && < 1.10,+ time >= 1.4 && < 1.12, parsec ==3.1.*,- syb >=0.3.7 && < 0.8+ syb >=0.3.7 && < 0.8,+ template-haskell >=2.0.0.0 && <2.17 GHC-Options: -O2+ default-language: Haskell2010 Test-suite main type: exitcode-stdio-1.0- build-depends: base >= 4.9 && < 4.13,+ build-depends: base >= 4.9 && < 4.16, hspec, dates hs-source-dirs: tests main-is: Spec.hs+ default-language: Haskell2010 Source-repository head type: git location: https://github.com/portnov/dates.git+