chronos 1.0.2 → 1.0.3
raw patch · 2 files changed
+33/−23 lines, 2 filesdep +semigroupsdep ~aesondep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: semigroups
Dependency ranges changed: aeson, base
API changes (from Hackage documentation)
+ Chronos: instance Data.Semigroup.Semigroup Chronos.Timespan
Files
- chronos.cabal +8/−7
- src/Chronos.hs +25/−16
chronos.cabal view
@@ -1,5 +1,5 @@ name: chronos-version: 1.0.2+version: 1.0.3 synopsis: A performant time library description: Performance-oriented time library for haskell. The main differences@@ -43,16 +43,17 @@ other-modules: Chronos.Internal.CTimespec build-depends:- base >= 4.8 && < 5- , vector >= 0.11 && < 0.13- , text >= 1.2 && < 1.3- , bytestring >= 0.10 && < 0.11+ base >= 4.9 && < 5+ , aeson >= 1.1 && < 1.4 , attoparsec >= 0.13 && < 0.14- , aeson >= 1.1 && < 1.3+ , bytestring >= 0.10 && < 0.11+ , clock >= 0.7 && < 0.8 , hashable >= 1.2 && < 1.3 , primitive >= 0.6 && < 0.7+ , semigroups >= 0.16 && < 0.19+ , text >= 1.2 && < 1.3 , torsor >= 0.1 && < 0.2- , clock >= 0.7 && < 0.8+ , vector >= 0.11 && < 0.13 default-language: Haskell2010 c-sources: src/cbits/hs-time.c
src/Chronos.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MagicHash #-}@@ -6,6 +7,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeInType #-} {-# LANGUAGE UnboxedTuples #-} {-# OPTIONS_GHC -Wall #-}@@ -198,7 +200,6 @@ import Data.Text (Text) import Data.Vector (Vector)-import Data.Monoid import Data.Attoparsec.Text (Parser) import Control.Monad import Data.Foldable@@ -216,26 +217,31 @@ import Foreign.Storable import Data.Hashable (Hashable) import Control.Exception (evaluate)-import qualified System.Clock as CLK import qualified Data.Aeson as AE import qualified Data.Aeson.Encoding as AEE import qualified Data.Aeson.Types as AET-import qualified Data.Text as Text-import qualified Data.Text.Read as Text-import qualified Data.Attoparsec.Text as AT import qualified Data.Attoparsec.ByteString.Char8 as AB-import qualified Data.Vector as Vector-import qualified Data.Text.Lazy.Builder as TB-import qualified Data.Text.Lazy.Builder.Int as TB+import qualified Data.Attoparsec.Text as AT import qualified Data.ByteString.Builder as BB import qualified Data.ByteString.Char8 as BC-import qualified Data.Text.Lazy as LT import qualified Data.ByteString.Lazy as LB-import qualified Data.Vector.Unboxed as UVector+import qualified Data.Semigroup as SG+import qualified Data.Text as Text+import qualified Data.Text.Lazy as LT+import qualified Data.Text.Lazy.Builder as TB+import qualified Data.Text.Lazy.Builder.Int as TB+import qualified Data.Text.Read as Text+import qualified Data.Vector as Vector import qualified Data.Vector.Generic as GVector-import qualified Data.Vector.Primitive as PVector import qualified Data.Vector.Generic.Mutable as MGVector+import qualified Data.Vector.Primitive as PVector+import qualified Data.Vector.Unboxed as UVector+import qualified System.Clock as CLK +#if !MIN_VERSION_base(4,11,0)+import Data.Semigroup (Semigroup, (<>))+#endif+ second :: Timespan second = Timespan 1000000000 @@ -1784,7 +1790,7 @@ else error "Enum.succ{Month}: tried to take succ of December" pred (Month x) = if x > 0 then Month (x - 1)- else error "Enum.pred{Month}: tried to take succ of January"+ else error "Enum.pred{Month}: tried to take pred of January" enumFrom x = enumFromTo x (Month 11) instance Bounded Month where@@ -1814,9 +1820,12 @@ newtype Timespan = Timespan { getTimespan :: Int64 } deriving (Show,Read,Eq,Ord,ToJSON,FromJSON,Additive) +instance Semigroup Timespan where+ (Timespan a) <> (Timespan b) = Timespan (a + b)+ instance Monoid Timespan where mempty = Timespan 0- mappend (Timespan a) (Timespan b) = Timespan (a + b)+ mappend = (SG.<>) instance Torsor Time Timespan where add (Timespan ts) (Time t) = Time (t + ts)@@ -2057,11 +2066,11 @@ instance ToJSON Datetime where toJSON = AE.String . encode_YmdHMS SubsecondPrecisionAuto hyphen- toEncoding x = AEE.unsafeToEncoding (BB.char7 '"' <> builderUtf8_YmdHMS SubsecondPrecisionAuto hyphen x <> BB.char7 '"')+ toEncoding x = AEE.unsafeToEncoding (BB.char7 '"' SG.<> builderUtf8_YmdHMS SubsecondPrecisionAuto hyphen x SG.<> BB.char7 '"') instance ToJSON Offset where toJSON = AE.String . encodeOffset OffsetFormatColonOn- toEncoding x = AEE.unsafeToEncoding (BB.char7 '"' <> builderOffsetUtf8 OffsetFormatColonOn x <> BB.char7 '"')+ toEncoding x = AEE.unsafeToEncoding (BB.char7 '"' SG.<> builderOffsetUtf8 OffsetFormatColonOn x SG.<> BB.char7 '"') instance FromJSON Offset where parseJSON = AE.withText "Offset" aesonParserOffset@@ -2069,7 +2078,7 @@ instance ToJSONKey Offset where toJSONKey = AE.ToJSONKeyText (encodeOffset OffsetFormatColonOn)- (\x -> AEE.unsafeToEncoding (BB.char7 '"' <> builderOffsetUtf8 OffsetFormatColonOn x <> BB.char7 '"'))+ (\x -> AEE.unsafeToEncoding (BB.char7 '"' SG.<> builderOffsetUtf8 OffsetFormatColonOn x SG.<> BB.char7 '"')) instance FromJSONKey Offset where fromJSONKey = AE.FromJSONKeyTextParser aesonParserOffset