core-data 0.3.4.0 → 0.3.6.0
raw patch · 3 files changed
+41/−4 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Core.Data.Clock: instance Core.Data.Clock.Instant Data.Time.Calendar.Days.Day
+ Core.Encoding.External: instance Core.Encoding.External.Externalize Data.Time.Calendar.Days.Day
Files
- core-data.cabal +2/−2
- lib/Core/Data/Clock.hs +26/−2
- lib/Core/Encoding/External.hs +13/−0
core-data.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: core-data-version: 0.3.4.0+version: 0.3.6.0 synopsis: Convenience wrappers around common data structures and encodings description: Wrappers around common data structures and encodings. .@@ -50,7 +50,7 @@ , base >=4.11 && <5 , bytestring , containers- , core-text >=0.3.7+ , core-text >=0.3.8 , hashable >=1.2 , hourglass , prettyprinter >=1.6.2
lib/Core/Data/Clock.hs view
@@ -46,8 +46,8 @@ ) where import Control.Applicative ((<|>))-import Core.Text.Rope import Core.Data.Format+import Core.Text.Rope import Data.Aeson qualified as Aeson (FromJSON (..), ToJSON (..), Value (..)) import Data.Aeson.Encoding qualified as Aeson (string) import Data.Aeson.Types qualified as Aeson (typeMismatch)@@ -65,7 +65,8 @@ ) import Data.Int (Int64) import Data.Maybe (maybeToList)-import Data.Time.Clock (UTCTime)+import Data.Time.Calendar (Day)+import Data.Time.Clock (UTCTime (UTCTime, utctDay, utctDayTime)) import Data.Time.Clock.POSIX ( POSIXTime, posixSecondsToUTCTime,@@ -166,12 +167,18 @@ nanosecond (who the hell has picoseconds of anything anyway?) if writing an instance of this type. +The most important instance is probably the 'UTCTime' one, as many other+Haskell libraries use this type to represent time.+ @since 0.3.3 -} class Instant a where fromTime :: Time -> a intoTime :: a -> Time +{- |+Number of nanoseconds since the epoch.+-} instance Instant Int64 where fromTime = unTime intoTime = Time@@ -193,6 +200,11 @@ convertToPosix :: Time -> POSIXTime convertToPosix = fromRational . (/ 1e9) . fromIntegral . unTime +{- |+Convert to the elapsed time with sub-second precision type from __hourglass__,+giving you ready access to that library's time formatting and calendar date+manipulation functions.+-} instance Instant H.ElapsedP where fromTime = convertToElapsed intoTime = convertFromElapsed@@ -207,6 +219,18 @@ convertToElapsed (Time ticks) = let (s, ns) = divMod ticks 1000000000 in H.ElapsedP (H.Elapsed (H.Seconds (s))) (H.NanoSeconds (ns))++{- |+This instance may be useful if you need to work with calendar dates with+functions from __time__. From here you would probably be interested in+'Data.Time.Calendar.toGregorian'. If you convert from a 'Day' it will be the+timestamp of midnight 00:00:00.0 on that date.++@since 0.3.5+-}+instance Instant Day where+ fromTime = utctDay . fromTime+ intoTime x = intoTime (UTCTime{utctDay = x, utctDayTime = 0}) instance Aeson.ToJSON Time where toEncoding = Aeson.string . H.timePrint ISO8601_Precise . convertToElapsed
lib/Core/Encoding/External.hs view
@@ -54,6 +54,8 @@ import Data.ByteString.Builder qualified as Builder import Data.Int (Int32, Int64) import Data.Scientific (FPFormat (Exponent), Scientific, formatScientific)+import Data.Time.Calendar qualified as Base (Day)+import Data.Time.Format.ISO8601 qualified as Base (formatParseM, formatShow, iso8601Format) import Data.UUID qualified as Uuid (UUID, fromText, toText) import Text.Read (readMaybe) @@ -200,6 +202,17 @@ instance Externalize Time where formatExternal = intoRope . show parseExternal = readMaybe . fromRope++{- |+Days are formatted as per ISO 8601:++@+2022-06-20+@+-}+instance Externalize Base.Day where+ formatExternal = intoRope . Base.formatShow Base.iso8601Format+ parseExternal = Base.formatParseM Base.iso8601Format . fromRope {- | Numbers are converted to scientific notation: