Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data NtpPacket = NtpPacket {}
- ntpPacketSize ∷ Int
- mkNtpPacket ∷ IO NtpPacket
- newtype NtpOffset = NtpOffset {}
- getCurrentTime ∷ IO Microsecond
- clockOffsetPure ∷ NtpPacket → Microsecond → NtpOffset
- clockOffset ∷ Microsecond → NtpPacket → IO (Maybe NtpOffset)
- realMcsToNtp ∷ Microsecond → (Word32, Word32)
- ntpToRealMcs ∷ Word32 → Word32 → Microsecond
- newtype Microsecond = Microsecond Integer
Documentation
NtpPacket | |
|
We only need first 48 bytes of a packet: reference: https://tools.ietf.org/html/rfc5905#section-7.3
is the difference between NTP time and local time.NtpOffset
Instances
Enum NtpOffset Source # | |
Defined in Network.NTP.Client.Packet | |
Num NtpOffset Source # | |
Integral NtpOffset Source # | |
Defined in Network.NTP.Client.Packet | |
Real NtpOffset Source # | |
Defined in Network.NTP.Client.Packet toRational ∷ NtpOffset → Rational # | |
Show NtpOffset Source # | |
Eq NtpOffset Source # | |
Ord NtpOffset Source # | |
Defined in Network.NTP.Client.Packet |
getCurrentTime ∷ IO Microsecond Source #
Helper function to get current time in Microsecond
.
∷ Microsecond |
|
→ NtpPacket | |
→ IO (Maybe NtpOffset) |
Compute clock offset unless the NTP packet was requested more than the given timeout.
realMcsToNtp ∷ Microsecond → (Word32, Word32) Source #
It is a partial function, since Microsecond ~ Integer
; it is well defined
for:
x < 2085978496 = (maxBound
Word32 * 1000000) - ntpTimestampDelta + 1`
@
(in microseconds; this is roughly 66 years, so we're fine untill 2036).
ntpToRealMcs ∷ Word32 → Word32 → Microsecond Source #
For pairs (x, y) :: (Word32, Word32)
with y `mod` 4294 == 0
it is
be right inverse of
. In general it is not injective (for that
we'd need to use realMsgToNtp
instead of Picosecond
).Microsecond
newtype Microsecond Source #