Copyright | (c) 2015-2016 Kim Altintop <kim.altintop@gmail.com> |
---|---|
License | MPL |
Maintainer | Kim Altintop <kim.altintop@gmail.com> |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Extensions |
|
Implementation of TAI64 labels as specified by http://cr.yp.to/libtai/tai64.html
Mainly useful for working with logfiles generated by "multilog" (part of the daemontools suite) or "svlogd" (part of the runit suite).
- data TAI64
- tai64 :: Word64 -> Word32 -> Word32 -> TAI64
- taiSecs :: TAI64 -> Word64
- taiNanos :: TAI64 -> Word32
- taiAttos :: TAI64 -> Word32
- data Label
- fromLabel :: Label -> TAI64
- addTAI64 :: DiffTime -> TAI64 -> TAI64
- diffTAI64 :: TAI64 -> TAI64 -> DiffTime
- sumTAI64 :: TAI64 -> TAI64 -> TAI64
- subTAI64 :: TAI64 -> TAI64 -> TAI64
- toUTCTime :: TAI64 -> UTCTime
- fromUTCTime :: UTCTime -> TAI64
- toPOSIXTime :: TAI64 -> POSIXTime
- fromPOSIXTime :: POSIXTime -> TAI64
- toText :: Label -> Text
- fromText :: Text -> Either String TAI64
- toByteString :: Label -> ByteString
- fromByteString :: ByteString -> Either String TAI64
- parse :: ParseInput a => Parser a TAI64
- parseText :: Parser Text TAI64
- parseByteString :: Parser ByteString TAI64
Documentation
Representation of a TAI64 label with full precision
Bounded TAI64 Source | |
Eq TAI64 Source | |
Ord TAI64 Source | |
Show TAI64 Source | |
Arbitrary TAI64 Source | |
Unbox TAI64 Source | |
Vector Vector TAI64 Source | |
MVector MVector TAI64 Source | |
data Vector TAI64 = V_TAI64 (Vector (Word64, Word32, Word32)) Source | |
data MVector s TAI64 = MV_TAI64 (MVector s (Word64, Word32, Word32)) Source |
tai64 :: Word64 -> Word32 -> Word32 -> TAI64 Source
Construct a TAI64
from seconds, nanoseconds and attoseconds
taiSecs :: TAI64 -> Word64 Source
Seconds of real time.
Integer s refers to * the TAI second beginning exactly 2^62 - s seconds before the beginning of 1970 TAI, if s is between 0 inclusive and 2^62 exclusive; * or the TAI second beginning exactly s - 2^62 seconds after the beginning of 1970 TAI, if s is between 2^62 inclusive and 2^63 exclusive. Integers 2^63 and larger are reserved for future extensions. Under many cosmological theories, the integers under 2^63 are adequate to cover the entire expected lifetime of the universe; in this case no extensions will be necessary.
A TAI64 label with precision as denoted by the data constructor. This is
used to render the "external" (cf. toText
, toByteString
) respectively
binary representation.
Eq Label Source | |
Ord Label Source | |
Show Label Source | |
Arbitrary Label Source | |
Binary Label Source | External representation of a
Properties: (Binary.decode . Binary.encode) x == x |
addTAI64 :: DiffTime -> TAI64 -> TAI64 Source
addTAI64 a b = a + b
Properties:
\d (PicosecondResolution t) -> addTAI64 d t === fromUTCTime (addUTCTime (realToFrac d) (toUTCTime t))
diffTAI64 :: TAI64 -> TAI64 -> DiffTime Source
diffTAI64 a b = a - b
Properties:
\(PicosecondResolution a) (PicosecondResolution b) -> b <= a ==> diffTAI64 a b === realToFrac (diffUTCTime (toUTCTime a) (toUTCTime b))
sumTAI64 :: TAI64 -> TAI64 -> TAI64 Source
sumTAI64 a b = a + b
Properties:
sumTAI64 a b >= a
sumTAI64 a minBound === a
sumTAI64 b a === sumTAI64 a b
(a `sumTAI64` b) `sumTAI64` c === a `sumTAI64` (b `sumTAI64` c)
subTAI64 :: TAI64 -> TAI64 -> TAI64 Source
subTAI64 a b = a - b
Properties:
subTAI64 a b <= a
b >= a ==> subTAI64 a b === minBound
subTAI64 a minBound === a
fromUTCTime :: UTCTime -> TAI64 Source
toPOSIXTime :: TAI64 -> POSIXTime Source
fromPOSIXTime :: POSIXTime -> TAI64 Source
toText :: Label -> Text Source
Render a textual (ie. hexadecimal) representation of the external
TAI64{N,NA} format of the given Label
Properties:
(fromText . toText) x === Right (fromLabel x)
fromText :: Text -> Either String TAI64 Source
Parse a TAI64
label from it's textual (hexadecimal) representation.
Properties:
let x' = toText x in fromText x' === fromText ("@" <> x')
toByteString :: Label -> ByteString Source
Render a textual (ie. hexadecimal) representation of the external
TAI64{N,NA} format of the given Label
Properties:
(fromByteString . toByteString) x === Right (fromLabel x)
fromByteString :: ByteString -> Either String TAI64 Source
Parse a TAI64
label from it's textual (hexadecimal) representation.
Properties:
let x' = toByteString x in fromByteString x' === fromByteString ("@" <> x')
parse :: ParseInput a => Parser a TAI64 Source
Attoparsec parser for the textual TAI64 format, generalized so it works for
both Text
and ByteString
input.
parseByteString :: Parser ByteString TAI64 Source
Type-specialisation of parse