Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Thyme.Clock
Description
Types and functions for UTC and UT1.
If you don't care about leap seconds, keep to UTCTime
and
NominalDiffTime
for your clock calculations, and you'll be fine.
Num
, Real
, Fractional
and RealFrac
instances for DiffTime
and
NominalDiffTime
are only available by importing Data.Thyme.Time. In
their stead are instances of AdditiveGroup
,
HasBasis
and VectorSpace
, with
.Scalar
DiffTime
≡ Scalar
NominalDiffTime
≡ Rational
Using fromSeconds
and toSeconds
to convert between TimeDiff
s and
other numeric types. If you really must coerce between DiffTime
and
NominalDiffTime
,
.view
(microseconds
. from
microseconds
)
UTCTime
is an instance of AffineSpace
, with
.Diff
UTCTime
≡ NominalDiffTime
UTCTime
is not Y294K-compliant. Please file a bug report on GitHub when
this becomes a problem.
Synopsis
- data UniversalTime
- modJulianDate :: Iso' UniversalTime Rational
- data DiffTime
- data UTCTime
- data UTCView = UTCTime {
- utctDay :: !Day
- utctDayTime :: !DiffTime
- utcTime :: Iso' UTCTime UTCView
- data NominalDiffTime
- getCurrentTime :: IO UTCTime
- class (HasBasis t, Basis t ~ (), Scalar t ~ Rational) => TimeDiff t where
- microseconds :: Iso' t Int64
- toSeconds :: (TimeDiff t, Fractional n) => t -> n
- fromSeconds :: (Real n, TimeDiff t) => n -> t
- toSeconds' :: TimeDiff t => t -> Rational
- fromSeconds' :: TimeDiff t => Rational -> t
- _utctDay :: Lens' UTCTime Day
- _utctDayTime :: Lens' UTCTime DiffTime
Universal Time
data UniversalTime Source #
The principal form of universal time, namely UT1.
UniversalTime
is defined by the rotation of the Earth around its axis
relative to the Sun. Thus the length of a day by this definition varies
from one to the next, and is never exactly 86400 SI seconds unlike
TAI or
AbsoluteTime
. The difference between UT1 and UTC is
DUT1.
Instances
modJulianDate :: Iso' UniversalTime Rational Source #
View UniversalTime
as a fractional number of days since the
Modified Julian Date epoch.
Absolute intervals
An absolute time interval as measured by a clock.
DiffTime
forms an AdditiveGroup
―so can be added using ^+^
(or ^-^
for subtraction), and also an instance of VectorSpace
―so can be scaled
using *^
, where
typeScalar
DiffTime
=Rational
Instances
UTC
Coördinated universal time:
the most common form of universal time for civil timekeeping. It is
synchronised with AbsoluteTime
and both tick in increments of SI
seconds, but UTC includes occasional leap-seconds so that it does not
drift too far from UniversalTime
.
UTCTime
is an instance of AffineSpace
, with
typeDiff
UTCTime
=NominalDiffTime
Use .+^
to add (or .-^
to subtract) time intervals of type
NominalDiffTime
, and .-.
to get the interval between UTCTime
s.
Performance
- Internally this is a 64-bit count of
microseconds
since the MJD epoch, so.+^
,.-^
and.-.
ought to be fairly fast. Issues
UTCTime
currently cannot represent leap seconds.
Instances
Bounded UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal | |
Enum UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal | |
Eq UTCTime Source # | |
Data UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> UTCTime -> c UTCTime gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c UTCTime dataTypeOf :: UTCTime -> DataType dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c UTCTime) dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UTCTime) gmapT :: (forall b. Data b => b -> b) -> UTCTime -> UTCTime gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UTCTime -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UTCTime -> r gmapQ :: (forall d. Data d => d -> u) -> UTCTime -> [u] gmapQi :: Int -> (forall d. Data d => d -> u) -> UTCTime -> u gmapM :: Monad m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime | |
Ord UTCTime Source # | |
Read UTCTime | |
Defined in Data.Thyme.Format | |
Show UTCTime | |
Ix UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal | |
Generic UTCTime Source # | |
Arbitrary UTCTime Source # | |
CoArbitrary UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal | |
ToJSON UTCTime Source # | |
FromJSON UTCTime Source # | |
Random UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal Methods randomR :: RandomGen g => (UTCTime, UTCTime) -> g -> (UTCTime, g) Source # random :: RandomGen g => g -> (UTCTime, g) Source # randomRs :: RandomGen g => (UTCTime, UTCTime) -> g -> [UTCTime] Source # randoms :: RandomGen g => g -> [UTCTime] Source # | |
Unbox UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal | |
AffineSpace UTCTime Source # | |
NFData UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal | |
ParseTime UTCTime Source # | |
FormatTime UTCTime Source # | |
Defined in Data.Thyme.Format Methods showsTime :: TimeLocale -> UTCTime -> (Char -> ShowS) -> Char -> ShowS Source # | |
Vector Vector UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal Methods basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) UTCTime -> m (Vector UTCTime) Source # basicUnsafeThaw :: PrimMonad m => Vector UTCTime -> m (Mutable Vector (PrimState m) UTCTime) Source # basicLength :: Vector UTCTime -> Int Source # basicUnsafeSlice :: Int -> Int -> Vector UTCTime -> Vector UTCTime Source # basicUnsafeIndexM :: Monad m => Vector UTCTime -> Int -> m UTCTime Source # basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) UTCTime -> Vector UTCTime -> m () Source # | |
MVector MVector UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal Methods basicLength :: MVector s UTCTime -> Int Source # basicUnsafeSlice :: Int -> Int -> MVector s UTCTime -> MVector s UTCTime Source # basicOverlaps :: MVector s UTCTime -> MVector s UTCTime -> Bool Source # basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) UTCTime) Source # basicInitialize :: PrimMonad m => MVector (PrimState m) UTCTime -> m () Source # basicUnsafeReplicate :: PrimMonad m => Int -> UTCTime -> m (MVector (PrimState m) UTCTime) Source # basicUnsafeRead :: PrimMonad m => MVector (PrimState m) UTCTime -> Int -> m UTCTime Source # basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) UTCTime -> Int -> UTCTime -> m () Source # basicClear :: PrimMonad m => MVector (PrimState m) UTCTime -> m () Source # basicSet :: PrimMonad m => MVector (PrimState m) UTCTime -> UTCTime -> m () Source # basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) UTCTime -> MVector (PrimState m) UTCTime -> m () Source # basicUnsafeMove :: PrimMonad m => MVector (PrimState m) UTCTime -> MVector (PrimState m) UTCTime -> m () Source # basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) UTCTime -> Int -> m (MVector (PrimState m) UTCTime) Source # | |
Thyme UTCTime UTCTime Source # | |
Defined in Data.Thyme.Time.Core | |
type Rep UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal type Rep UTCTime = D1 ('MetaData "UTCTime" "Data.Thyme.Clock.Internal" "thyme-0.3.5.5-8yk8awDjzEHHYSq2xJCwO3" 'True) (C1 ('MetaCons "UTCRep" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NominalDiffTime))) | |
newtype Vector UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal | |
type Diff UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal | |
newtype MVector s UTCTime Source # | |
Defined in Data.Thyme.Clock.Internal |
Unpacked UTCTime
, partly for compatibility with time
.
Constructors
UTCTime | |
Fields
|
Instances
Eq UTCView Source # | |
Data UTCView Source # | |
Defined in Data.Thyme.Clock.Internal Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> UTCView -> c UTCView gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c UTCView dataTypeOf :: UTCView -> DataType dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c UTCView) dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UTCView) gmapT :: (forall b. Data b => b -> b) -> UTCView -> UTCView gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UTCView -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UTCView -> r gmapQ :: (forall d. Data d => d -> u) -> UTCView -> [u] gmapQi :: Int -> (forall d. Data d => d -> u) -> UTCView -> u gmapM :: Monad m => (forall d. Data d => d -> m d) -> UTCView -> m UTCView gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCView -> m UTCView gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCView -> m UTCView | |
Ord UTCView Source # | |
Read UTCView | |
Defined in Data.Thyme.Format | |
Show UTCView Source # | |
Generic UTCView Source # | |
Unbox UTCView Source # | |
Defined in Data.Thyme.Clock.Internal | |
NFData UTCView Source # | |
Defined in Data.Thyme.Clock.Internal | |
Vector Vector UTCView Source # | |
Defined in Data.Thyme.Clock.Internal Methods basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) UTCView -> m (Vector UTCView) Source # basicUnsafeThaw :: PrimMonad m => Vector UTCView -> m (Mutable Vector (PrimState m) UTCView) Source # basicLength :: Vector UTCView -> Int Source # basicUnsafeSlice :: Int -> Int -> Vector UTCView -> Vector UTCView Source # basicUnsafeIndexM :: Monad m => Vector UTCView -> Int -> m UTCView Source # basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) UTCView -> Vector UTCView -> m () Source # | |
MVector MVector UTCView Source # | |
Defined in Data.Thyme.Clock.Internal Methods basicLength :: MVector s UTCView -> Int Source # basicUnsafeSlice :: Int -> Int -> MVector s UTCView -> MVector s UTCView Source # basicOverlaps :: MVector s UTCView -> MVector s UTCView -> Bool Source # basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) UTCView) Source # basicInitialize :: PrimMonad m => MVector (PrimState m) UTCView -> m () Source # basicUnsafeReplicate :: PrimMonad m => Int -> UTCView -> m (MVector (PrimState m) UTCView) Source # basicUnsafeRead :: PrimMonad m => MVector (PrimState m) UTCView -> Int -> m UTCView Source # basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) UTCView -> Int -> UTCView -> m () Source # basicClear :: PrimMonad m => MVector (PrimState m) UTCView -> m () Source # basicSet :: PrimMonad m => MVector (PrimState m) UTCView -> UTCView -> m () Source # basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) UTCView -> MVector (PrimState m) UTCView -> m () Source # basicUnsafeMove :: PrimMonad m => MVector (PrimState m) UTCView -> MVector (PrimState m) UTCView -> m () Source # basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) UTCView -> Int -> m (MVector (PrimState m) UTCView) Source # | |
Thyme UTCTime UTCView Source # | |
Defined in Data.Thyme.Time.Core | |
type Rep UTCView Source # | |
Defined in Data.Thyme.Clock.Internal type Rep UTCView = D1 ('MetaData "UTCView" "Data.Thyme.Clock.Internal" "thyme-0.3.5.5-8yk8awDjzEHHYSq2xJCwO3" 'False) (C1 ('MetaCons "UTCTime" 'PrefixI 'True) (S1 ('MetaSel ('Just "utctDay") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Day) :*: S1 ('MetaSel ('Just "utctDayTime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 DiffTime))) | |
newtype Vector UTCView Source # | |
newtype MVector s UTCView Source # | |
Defined in Data.Thyme.Clock.Internal |
utcTime :: Iso' UTCTime UTCView Source #
View UTCTime
as an UTCView
, comprising a Day
along with
a DiffTime
offset since midnight.
This is an improper lens: utctDayTime
offsets outside the range of
[
will carry over into the day part, with the
expected behaviour.zeroV
, posixDayLength
)
data NominalDiffTime Source #
A time interval as measured by UTC, that does not take leap-seconds into account.
For instance, the difference between 23:59:59
and 00:00:01
on the
following day is always 2 seconds of NominalDiffTime
, regardless of
whether a leap-second took place.
NominalDiffTime
forms an AdditiveGroup
―so can be added using ^+^
(or ^-^
for subtraction), and also an instance of VectorSpace
―so can
be scaled using *^
, where
typeScalar
NominalDiffTime
=Rational
Instances
getCurrentTime :: IO UTCTime Source #
Get the current UTC time from the system clock.
Time interval conversion
class (HasBasis t, Basis t ~ (), Scalar t ~ Rational) => TimeDiff t where Source #
Time intervals, encompassing both DiffTime
and NominalDiffTime
.
Issues
- Still affected by http://hackage.haskell.org/trac/ghc/ticket/7611?
Instances
TimeDiff DiffTime Source # | |
Defined in Data.Thyme.Clock.Internal Methods microseconds :: Iso' DiffTime Int64 Source # | |
TimeDiff NominalDiffTime Source # | |
Defined in Data.Thyme.Clock.Internal Methods microseconds :: Iso' NominalDiffTime Int64 Source # |
toSeconds :: (TimeDiff t, Fractional n) => t -> n Source #
Convert a time interval to some Fractional
type.
fromSeconds :: (Real n, TimeDiff t) => n -> t Source #
Make a time interval from some Real
type.
Performance
- Try to make sure
n
is one ofFloat
,Double
,Int
,Int64
orInteger
, for which rewriteRULES
have been provided.
toSeconds' :: TimeDiff t => t -> Rational Source #
Type-restricted toSeconds
to avoid constraint-defaulting warnings.
fromSeconds' :: TimeDiff t => Rational -> t Source #
Type-restricted fromSeconds
to avoid constraint-defaulting warnings.