attoparsec-iso8601 1.1.0.0 → 1.1.0.1
raw patch · 3 files changed
+54/−92 lines, 3 filesdep +integer-conversiondep −base-compat-batteriesdep ~basedep ~textPVP ok
version bump matches the API change (PVP)
Dependencies added: integer-conversion
Dependencies removed: base-compat-batteries
Dependency ranges changed: base, text
API changes (from Hackage documentation)
Files
- attoparsec-iso8601.cabal +42/−28
- src/Data/Attoparsec/Time.hs +9/−61
- src/Data/Attoparsec/Time/Internal.hs +3/−3
attoparsec-iso8601.cabal view
@@ -1,38 +1,52 @@-name: attoparsec-iso8601-version: 1.1.0.0-synopsis: Parsing of ISO 8601 dates, originally from aeson-description: Parsing of ISO 8601 dates, originally from aeson.-license: BSD3-license-file: LICENSE-category: Parsing-copyright: (c) 2011-2016 Bryan O'Sullivan- (c) 2011 MailRank, Inc.-author: Bryan O'Sullivan <bos@serpentine.com>-maintainer: Adam Bergmark <adam@bergmark.nl>-stability: experimental-cabal-version: >=1.10-homepage: https://github.com/haskell/aeson-bug-reports: https://github.com/haskell/aeson/issues-build-type: Simple-tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC ==9.2.3, GHC==9.4.1+name: attoparsec-iso8601+version: 1.1.0.1+synopsis: Parsing of ISO 8601 dates, originally from aeson+description: Parsing of ISO 8601 dates, originally from aeson.+license: BSD3+license-file: LICENSE+category: Parsing+copyright:+ (c) 2011-2016 Bryan O'Sullivan+ (c) 2011 MailRank, Inc.++author: Bryan O'Sullivan <bos@serpentine.com>+maintainer: Adam Bergmark <adam@bergmark.nl>+stability: experimental+cabal-version: 1.12+homepage: https://github.com/haskell/aeson+bug-reports: https://github.com/haskell/aeson/issues+build-type: Simple+tested-with:+ GHC ==8.2.2+ || ==8.4.4+ || ==8.6.5+ || ==8.8.4+ || ==8.10.7+ || ==9.0.2+ || ==9.2.8+ || ==9.4.7+ || ==9.6.3+ || ==9.8.1+ extra-source-files:- README.md changelog.md+ README.md library- hs-source-dirs: src- default-language: Haskell2010- ghc-options: -Wall+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall exposed-modules:- Data.Attoparsec.Time.Internal Data.Attoparsec.Time+ Data.Attoparsec.Time.Internal+ build-depends:- attoparsec >= 0.14.2 && < 0.15,- base >= 4.9 && < 5,- base-compat-batteries >= 0.10.0 && < 0.13,- time-compat >= 1.9.4 && < 1.10,- text >= 1.2.3.0 && < 1.3.0.0 || >= 2.0 && <2.1,- time >= 1.6.0.1 && < 1.13+ attoparsec >=0.14.2 && <0.15+ , base >=4.10.0.0 && <5+ , integer-conversion >=0.1 && <0.2+ , text >=1.2.3.0 && <1.3.0.0 || >=2.0 && <2.2+ , time >=1.6.0.1 && <1.13+ , time-compat >=1.9.4 && <1.10 source-repository head type: git
src/Data/Attoparsec/Time.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE BangPatterns #-}-{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ScopedTypeVariables #-} -- | -- Module: Data.Aeson.Parser.Time@@ -24,16 +23,13 @@ , quarter ) where -import Prelude.Compat- import Control.Applicative ((<|>))-import Control.Monad (void, when)-import Data.Attoparsec.Text (Parser, char, digit, option, anyChar, peekChar, peekChar', takeWhile1, satisfy)-import Data.Attoparsec.Time.Internal (toPico)+import Data.Attoparsec.Text (Parser, char, digit, option, anyChar, peekChar, takeWhile1, satisfy) import Data.Bits ((.&.)) import Data.Char (isDigit, ord)-import Data.Fixed (Pico)+import Data.Fixed (Pico, Fixed (..)) import Data.Int (Int64)+import Data.Integer.Conversion (textToInteger) import Data.Maybe (fromMaybe) import Data.Time.Calendar (Day, fromGregorianValid) import Data.Time.Calendar.Compat (Year)@@ -95,7 +91,7 @@ if T.length ds < 4 then fail "expected year with at least 4 digits" else- pure (txtToInteger ds)+ pure (textToInteger ds) -- | Parse a two-digit integer (e.g. day of month, hour). twoDigits :: Parser Int@@ -129,7 +125,7 @@ return $! parsePicos real t _ -> return $! fromIntegral real where- parsePicos a0 t = toPico (fromIntegral (t' * 10^n))+ parsePicos a0 t = MkFixed (fromIntegral (t' * 10^n)) where T n t' = T.foldl' step (T 12 (fromIntegral a0)) t step ma@(T m a) c | m <= 0 = ma@@ -137,10 +133,11 @@ -- | Parse a time zone, and return 'Nothing' if the offset from UTC is -- zero. (This makes some speedups possible.)+--+-- The accepted formats are @Z@, @+HH@, @+HHMM@, or @+HH:MM@.+-- timeZone :: Parser (Maybe Local.TimeZone) timeZone = do- let maybeSkip c = do ch <- peekChar'; when (ch == c) (void anyChar)- maybeSkip ' ' ch <- satisfy $ \c -> c == 'Z' || c == '+' || c == '-' if ch == 'Z' then return Nothing@@ -181,6 +178,7 @@ in return (UTCTime d tt) Just tz -> return $! Local.localTimeToUTC tz lt + -- | Parse a date with time zone info. Acceptable formats: -- -- @YYYY-MM-DD HH:MM Z@@@ -197,53 +195,3 @@ utc :: Local.TimeZone utc = Local.TimeZone 0 False ""-------------------- Copy-pasted and adapted from base --------------------------txtToInteger :: T.Text -> Integer-txtToInteger bs- | l > 40 = valInteger 10 l [ fromIntegral (ord w - 48) | w <- T.unpack bs ]- | otherwise = txtToIntegerSimple bs- where- l = T.length bs--txtToIntegerSimple :: T.Text -> Integer-txtToIntegerSimple = T.foldl' step 0 where- step a b = a * 10 + fromIntegral (ord b - 48) -- 48 = '0'---- A sub-quadratic algorithm for Integer. Pairs of adjacent radix b--- digits are combined into a single radix b^2 digit. This process is--- repeated until we are left with a single digit. This algorithm--- performs well only on large inputs, so we use the simple algorithm--- for smaller inputs.-valInteger :: Integer -> Int -> [Integer] -> Integer-valInteger = go- where- go :: Integer -> Int -> [Integer] -> Integer- go _ _ [] = 0- go _ _ [d] = d- go b l ds- | l > 40 = b' `seq` go b' l' (combine b ds')- | otherwise = valSimple b ds- where- -- ensure that we have an even number of digits- -- before we call combine:- ds' = if even l then ds else 0 : ds- b' = b * b- l' = (l + 1) `quot` 2-- combine b (d1 : d2 : ds) = d `seq` (d : combine b ds)- where- d = d1 * b + d2- combine _ [] = []- combine _ [_] = errorWithoutStackTrace "this should not happen"---- The following algorithm is only linear for types whose Num operations--- are in constant time.-valSimple :: Integer -> [Integer] -> Integer-valSimple base = go 0- where- go r [] = r- go r (d : ds) = r' `seq` go r' ds- where- r' = r * base + fromIntegral d
src/Data/Attoparsec/Time/Internal.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE NoImplicitPrelude #-} -- | -- Module: Data.Aeson.Internal.Time -- Copyright: (c) 2015-2016 Bryan O'Sullivan@@ -16,7 +15,6 @@ , toTimeOfDay64 ) where -import Prelude.Compat import Data.Fixed (Fixed(MkFixed), Pico) import Data.Int (Int64)@@ -25,9 +23,11 @@ toPico :: Integer -> Pico toPico = MkFixed+{-# DEPRECATED toPico "Use MkFixed" #-} fromPico :: Pico -> Integer fromPico (MkFixed i) = i+{-# DEPRECATED fromPico "Use MkFixed" #-} -- | Like TimeOfDay, but using a fixed-width integer for seconds. data TimeOfDay64 = TOD {-# UNPACK #-} !Int@@ -46,4 +46,4 @@ pico = fromIntegral . diffTimeToPicoseconds toTimeOfDay64 :: TimeOfDay -> TimeOfDay64-toTimeOfDay64 (TimeOfDay h m s) = TOD h m (fromIntegral (fromPico s))+toTimeOfDay64 (TimeOfDay h m (MkFixed s)) = TOD h m (fromIntegral s)