7788-- Stability : experimental
99-- Portability : GHC
10- --
11- -- 'TimeSpec' can store upto a duration of ~292 billion years at nanosecond
12- -- precision. An 'Int64' data type is much faster to manipulate but has a
13- -- smaller maximum limit (~292 years) at nanosecond precision. An 'Integer'
14- -- type can possibly be used for unbounded fixed precision time. 'Double' can
15- -- be used for floating precision time.
1610
1711module Streamly.Internal.Data.Time.TimeSpec
1812 (
2418#include "config.h"
2519#endif
2620
27- #include "Streamly/Internal/Data/Time/config-clock.h"
21+ #include "Streamly/Internal/Data/Time/Clock/ config-clock.h"
2822
2923#include "MachDeps.h"
3024
@@ -50,24 +44,20 @@ tenPower9 = 1000000000
5044-- TimeSpec
5145-------------------------------------------------------------------------------
5246
53- -- XXX Should we use "SystemTime" from the "time" package instead?
54- --
55- -- | 'TimeSpec' can hold up to ~292 billion years at nanosecond precision.
47+ -- | 'TimeSpec' can hold time values up to ~292 billion years at nanosecond
48+ -- precision.
5649--
57- -- In addition to using the 'TimeSpec' constructor you can also use
58- -- 'fromInteger' from the 'Num' type class to create a 'TimeSpec' from
59- -- nanoseconds. Like any 'Num', 'TimeSpec' can be negative.
50+ -- Use 'fromInteger' from the Num instance to create 'TimeSpec' from
51+ -- nanoseconds. Use 'Eq' and 'Ord' instances for comparisons. Use the 'Num'
52+ -- instance to perform arithmetic operations.
6053--
6154-- Note, we assume that 'nsec' is always less than 10^9. Also, when 'TimeSpec'
6255-- is negative then both 'sec' and 'nsec' must be negative.
63- -- TODO: Use smart constructors to enforce the assumptions.
64- --
65- -- Use 'Eq' and 'Ord' instances for comparisons and the 'Num' instance to
66- -- perform arithmetic operations on 'TimeSpec'.
67- --
56+
57+ -- XXX Use smart constructors to enforce these assumptions.
6858data TimeSpec = TimeSpec
6959 { sec :: {-# UNPACK #-} ! Int64 -- ^ seconds
70- -- XXX this could be Int32 instead
60+ -- This could be Int32 instead but Int64 is as good.
7161 , nsec :: {-# UNPACK #-} ! Int64 -- ^ nanoseconds
7262 } deriving (Eq , Read , Show )
7363
@@ -101,6 +91,7 @@ adjustSign t@(TimeSpec s ns)
10191timeSpecToInteger :: TimeSpec -> Integer
10292timeSpecToInteger (TimeSpec s ns) = toInteger $ s * tenPower9 + ns
10393
94+ -- XXX Error on overflow?
10495-- | Note that the arithmetic operations may overflow silently.
10596instance Num TimeSpec where
10697 {-# INLINE (+) #-}
0 commit comments