-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A pragmatic time and date library.
--
-- This library aims to supply you with common types and operations for
-- working with time and date.
--
--
-- - Parsing and rendering common formats like ISO8601 and
-- RFC3339.
-- - Modifying dates and times in a way that is easy to understand and
-- not overengineered (srsly, who needs something else than the Gregorian
-- Calendar?)
-- - A set of classes that provide interfaces for your own application
-- specific or maybe more efficient time and date types. Implement the
-- interfaces and get all the parsing and rendering functions for
-- free!
--
--
-- This is a work in progress!
--
-- Try it out and play with it. Tell me what you think about the API
-- design and naming, but __DON'T USE IT IN PRODUCTION YET!__
--
-- Bug reports or (even better) tests are welcome.
@package utc
@version 0.1.0.0
module Data.UTC.Internal
daysToYearMonthDay :: Integer -> (Integer, Integer, Integer)
-- | Convert Year-Month-Day to since 0000-01-01 in the Gregorian Calendar
--
--
-- - year 0 is a leap year
-- - year 400 is a leap year
-- - year 100,200,300 is not a leap year
-- - year / 4 is a leap year
-- - year (-4) (5 BC) is a leap year
--
yearMonthDayToDays :: (Integer, Integer, Integer) -> Integer
yearToDays :: Integer -> Integer
daysToYear :: Integer -> Integer
deltaUnixEpochCommonEpoch :: Rational
isValidDate :: (Integer, Integer, Integer) -> Bool
secsPerDay :: Integer
secsPerHour :: Integer
secsPerMinute :: Integer
minsPerHour :: Integer
hoursPerDay :: Integer
monthsPerYear :: Integer
module Data.UTC.Class.IsUnixTime
-- | This class is for types that have a well-defined mapping to and from
-- the Unix Time system (based on UTC).
--
-- Beware: It is a common misconception that the Unix time in
-- general counts SI seconds since 1970-01-01T00:00:00Z. There is
-- a common definition that may be called Unix time based on UTC:
-- In general, the second boundaries match with UTC, but in the event of
-- a positive (or negative) leap second the Unix second has a duration of
-- 2 (or 0) SI seconds. This library is in accordance with this
-- definition. This definition can also be understood as "ignoring leap
-- seconds" (a Unix day therefore always has 86400 Unix seconds).
--
-- The concrete behaviour of your system clock is implementation
-- dependant.
class IsUnixTime t
unixSeconds :: IsUnixTime t => t -> Rational
fromUnixSeconds :: (IsUnixTime t, Monad m) => Rational -> m t
module Data.UTC.Class.HasUnixTime
-- | This class defines an interface for contexts that can be asked for a
-- timestamp.
--
-- Most users are likely to just need the IO instance, but you
-- might think of other instances:
--
--
-- - A wrapper around the system clock with internal state that ensures
-- strict monotonically increasing values.
-- - A custom monadic computation that needs time, but should not be
-- given IO access.
-- - Testing contexts where you might want to inject and test specific
-- timestamps.
--
class HasUnixTime m
getUnixTime :: (HasUnixTime m, Monad m, IsUnixTime a) => m a
instance [safe] HasUnixTime IO
module Data.UTC.Class.IsTime
-- | This class captures the concept of a 24-hour clock time during a day.
class IsTime t where addHours h t = setHour hors t where h' = h + (hour t) hors = h' `mod` hoursPerDay addMinutes m t = setMinute mins t >>= addHours hors where m' = m + (minute t) mins = m' `mod` minsPerHour hors = m' `div` minsPerHour addSeconds s t = setSecond secs t >>= addMinutes mins where s' = s + (second t) secs = s' `mod` secsPerMinute mins = s' `div` secsPerMinute addSecondFractions f t | f == 0 = return t | f >= 0 = setSecondFraction frcs t >>= addSeconds secs | otherwise = setSecondFraction (frcs + 1.0) t >>= addSeconds (secs - 1) where f' = f + (secondFraction t) frcs = f' - (truncate f' % 1) secs = truncate f'
hour :: IsTime t => t -> Integer
minute :: IsTime t => t -> Integer
second :: IsTime t => t -> Integer
secondFraction :: IsTime t => t -> Rational
setHour :: (IsTime t, Monad m) => Integer -> t -> m t
setMinute :: (IsTime t, Monad m) => Integer -> t -> m t
setSecond :: (IsTime t, Monad m) => Integer -> t -> m t
setSecondFraction :: (IsTime t, Monad m) => Rational -> t -> m t
addHours :: (IsTime t, Monad m) => Integer -> t -> m t
addMinutes :: (IsTime t, Monad m) => Integer -> t -> m t
addSeconds :: (IsTime t, Monad m) => Integer -> t -> m t
addSecondFractions :: (IsTime t, Monad m) => Rational -> t -> m t
module Data.UTC.Class.Midnight
-- | The beginning of a day: 00:00:00
class Midnight t
midnight :: Midnight t => t
module Data.UTC.Type.Time
-- | This type represents time instants during a day (00:00:00 -
-- 23:59:59.999..) with arbitrary precision (uses Integer
-- internally).
--
--
-- - The internal structure is not exposed to avoid the creation of
-- invalid values. Use midnight or a parser to construct
-- values.
-- - The instance of Show is only meant for debugging purposes
-- and is subject to change.
--
data Time
midnight :: Midnight t => t
instance Eq Time
instance Ord Time
instance Show Time
instance IsTime Time
instance IsUnixTime Time
instance Midnight Time
module Data.UTC.Class.Epoch
-- | The instant in time also known as the epoch:
-- 1970-01-01T00:00:00Z
class Epoch t
epoch :: Epoch t => t
module Data.UTC.Class.IsDate
-- | This class captures the behaviour of the Proleptic Gregorian
-- Calendar.
--
-- Without any exception the following holds:
--
--
-- - A regular year has 365 days and the corresponding February has 28
-- days.
-- - A leap year has 366 days and the corresponding February has 29
-- days.
-- - A year that is a multiple of 400 is a leap year.
-- - A year that is a multiple of 100 but not of 400 is not a leap
-- year.
-- - A year that is a multiple of 4 but not of 100 is a leap year.
--
class Epoch t => IsDate t where addYears ys t = if isValidDate (year t + ys, month t, day t) then setYear (year t + ys) t else setYear (year t + ys) =<< setDay (day t - 1) t addMonths ms t = setDay 1 t >>= setYear y >>= setMonth m >>= setDay d where ym = (year t * monthsPerYear) + (month t - 1) + ms y = ym `div` monthsPerYear m = (ym `mod` monthsPerYear) + 1 d' = day t d | isValidDate (y, m, d') = d' | isValidDate (y, m, d' - 1) = d' - 1 | isValidDate (y, m, d' - 2) = d' - 2 | otherwise = d' - 3 addDays ds t = setDay 1 t >>= setYear y >>= setMonth m >>= setDay d where ds' = yearMonthDayToDays (year t, month t, day t) (y, m, d) = daysToYearMonthDay (ds' + ds)
year :: IsDate t => t -> Integer
month :: IsDate t => t -> Integer
day :: IsDate t => t -> Integer
setYear :: (IsDate t, Monad m) => Integer -> t -> m t
setMonth :: (IsDate t, Monad m) => Integer -> t -> m t
setDay :: (IsDate t, Monad m) => Integer -> t -> m t
addYears :: (IsDate t, Monad m) => Integer -> t -> m t
addMonths :: (IsDate t, Monad m) => Integer -> t -> m t
addDays :: (IsDate t, Monad m) => Integer -> t -> m t
module Data.UTC.Type.Date
-- | This type represents dates in the Proleptic Gregorian Calendar.
--
--
-- - It can represent any date in the past and in the future by using
-- Integer internally.
-- - The internal structure is not exposed to avoid the construction of
-- invalid values. Use epoch or a parser to construct values.
-- - The instance of Show is only meant for debugging purposes
-- and is subject to change.
--
data Date
instance Eq Date
instance Ord Date
instance Show Date
instance IsDate Date
instance IsUnixTime Date
instance Epoch Date
module Data.UTC.Type.Local
-- | This type is used to extend UTC time types by a local offset in
-- seconds (positive or negative).
--
-- Beware: A local offset is not a time zone. It is just a fix
-- period of time. In contrast to a time zone this does not take summer
-- or winter time into account.
data Local time
Local :: time -> Maybe Rational -> Local time
-- | The time to be interpreted as UTC+00:00 (Western
-- European Time)
utc :: Local time -> time
-- |
-- - Nothing The local offset is unknown (behaves like
-- Western European Time)
-- - Just 0 UTC+00:00 (Western European
-- Time)
-- - Just 3600 UTC+01:00 (Central European
-- Time)
--
offset :: Local time -> Maybe Rational
unknown :: t -> Local t
instance [safe] IsTime (Local Time)
instance [safe] Bounded t => Bounded (Local t)
instance [safe] Functor Local
instance [safe] Midnight t => Midnight (Local t)
instance [safe] Epoch t => Epoch (Local t)
instance [safe] Ord t => Ord (Local t)
instance [safe] Eq t => Eq (Local t)
module Data.UTC.Format.Rfc3339
class Rfc3339Parser a
parseRfc3339 :: (Rfc3339Parser a, Monad m, IsDate t, IsTime t, Epoch t) => a -> m (Local t)
class Rfc3339Renderer a
renderRfc3339 :: (Rfc3339Renderer a, Monad m, IsDate t, IsTime t, Epoch t) => Local t -> m a
rfc3339Parser :: (IsDate t, IsTime t) => Parser (Local t)
rfc3339Builder :: (Monad m, IsDate t, IsTime t) => Local t -> m Builder
instance Rfc3339Renderer [Char]
instance Rfc3339Renderer Text
instance Rfc3339Renderer Text
instance Rfc3339Renderer ByteString
instance Rfc3339Renderer ByteString
instance Rfc3339Parser [Char]
instance Rfc3339Parser Text
instance Rfc3339Parser Text
instance Rfc3339Parser ByteString
instance Rfc3339Parser ByteString
module Data.UTC.Type.DateTime
-- | A time representation based on a Date and the Time of
-- the day.
--
--
-- - The type uses multiprecision integers internally and is able to
-- represent any UTC date in the past and in the future with arbitrary
-- precision (apart from the time span within a leap second).
-- - The instances of IsString and Show are only meant
-- for debugging purposes and default to epoch in case of failure.
-- Don't rely on their behaviour!
--
data DateTime
DateTime :: Date -> Time -> DateTime
date :: DateTime -> Date
time :: DateTime -> Time
instance Eq DateTime
instance Ord DateTime
instance IsTime (Local DateTime)
instance IsDate (Local DateTime)
instance IsTime DateTime
instance IsDate DateTime
instance IsUnixTime DateTime
instance Epoch DateTime
instance IsString DateTime
instance Show (Local DateTime)
instance Show DateTime
module Data.UTC.Type
module Data.UTC.Class
module Data.UTC
-- | This class captures the behaviour of the Proleptic Gregorian
-- Calendar.
--
-- Without any exception the following holds:
--
--
-- - A regular year has 365 days and the corresponding February has 28
-- days.
-- - A leap year has 366 days and the corresponding February has 29
-- days.
-- - A year that is a multiple of 400 is a leap year.
-- - A year that is a multiple of 100 but not of 400 is not a leap
-- year.
-- - A year that is a multiple of 4 but not of 100 is a leap year.
--
class Epoch t => IsDate t where addYears ys t = if isValidDate (year t + ys, month t, day t) then setYear (year t + ys) t else setYear (year t + ys) =<< setDay (day t - 1) t addMonths ms t = setDay 1 t >>= setYear y >>= setMonth m >>= setDay d where ym = (year t * monthsPerYear) + (month t - 1) + ms y = ym `div` monthsPerYear m = (ym `mod` monthsPerYear) + 1 d' = day t d | isValidDate (y, m, d') = d' | isValidDate (y, m, d' - 1) = d' - 1 | isValidDate (y, m, d' - 2) = d' - 2 | otherwise = d' - 3 addDays ds t = setDay 1 t >>= setYear y >>= setMonth m >>= setDay d where ds' = yearMonthDayToDays (year t, month t, day t) (y, m, d) = daysToYearMonthDay (ds' + ds)
year :: IsDate t => t -> Integer
month :: IsDate t => t -> Integer
day :: IsDate t => t -> Integer
setYear :: (IsDate t, Monad m) => Integer -> t -> m t
setMonth :: (IsDate t, Monad m) => Integer -> t -> m t
setDay :: (IsDate t, Monad m) => Integer -> t -> m t
addYears :: (IsDate t, Monad m) => Integer -> t -> m t
addMonths :: (IsDate t, Monad m) => Integer -> t -> m t
addDays :: (IsDate t, Monad m) => Integer -> t -> m t
-- | This class captures the concept of a 24-hour clock time during a day.
class IsTime t where addHours h t = setHour hors t where h' = h + (hour t) hors = h' `mod` hoursPerDay addMinutes m t = setMinute mins t >>= addHours hors where m' = m + (minute t) mins = m' `mod` minsPerHour hors = m' `div` minsPerHour addSeconds s t = setSecond secs t >>= addMinutes mins where s' = s + (second t) secs = s' `mod` secsPerMinute mins = s' `div` secsPerMinute addSecondFractions f t | f == 0 = return t | f >= 0 = setSecondFraction frcs t >>= addSeconds secs | otherwise = setSecondFraction (frcs + 1.0) t >>= addSeconds (secs - 1) where f' = f + (secondFraction t) frcs = f' - (truncate f' % 1) secs = truncate f'
hour :: IsTime t => t -> Integer
minute :: IsTime t => t -> Integer
second :: IsTime t => t -> Integer
secondFraction :: IsTime t => t -> Rational
setHour :: (IsTime t, Monad m) => Integer -> t -> m t
setMinute :: (IsTime t, Monad m) => Integer -> t -> m t
setSecond :: (IsTime t, Monad m) => Integer -> t -> m t
setSecondFraction :: (IsTime t, Monad m) => Rational -> t -> m t
addHours :: (IsTime t, Monad m) => Integer -> t -> m t
addMinutes :: (IsTime t, Monad m) => Integer -> t -> m t
addSeconds :: (IsTime t, Monad m) => Integer -> t -> m t
addSecondFractions :: (IsTime t, Monad m) => Rational -> t -> m t
-- | This class is for types that have a well-defined mapping to and from
-- the Unix Time system (based on UTC).
--
-- Beware: It is a common misconception that the Unix time in
-- general counts SI seconds since 1970-01-01T00:00:00Z. There is
-- a common definition that may be called Unix time based on UTC:
-- In general, the second boundaries match with UTC, but in the event of
-- a positive (or negative) leap second the Unix second has a duration of
-- 2 (or 0) SI seconds. This library is in accordance with this
-- definition. This definition can also be understood as "ignoring leap
-- seconds" (a Unix day therefore always has 86400 Unix seconds).
--
-- The concrete behaviour of your system clock is implementation
-- dependant.
class IsUnixTime t
unixSeconds :: IsUnixTime t => t -> Rational
fromUnixSeconds :: (IsUnixTime t, Monad m) => Rational -> m t
-- | The instant in time also known as the epoch:
-- 1970-01-01T00:00:00Z
class Epoch t
epoch :: Epoch t => t
-- | The beginning of a day: 00:00:00
class Midnight t
midnight :: Midnight t => t
-- | This class defines an interface for contexts that can be asked for a
-- timestamp.
--
-- Most users are likely to just need the IO instance, but you
-- might think of other instances:
--
--
-- - A wrapper around the system clock with internal state that ensures
-- strict monotonically increasing values.
-- - A custom monadic computation that needs time, but should not be
-- given IO access.
-- - Testing contexts where you might want to inject and test specific
-- timestamps.
--
class HasUnixTime m
getUnixTime :: (HasUnixTime m, Monad m, IsUnixTime a) => m a
-- | This type represents dates in the Proleptic Gregorian Calendar.
--
--
-- - It can represent any date in the past and in the future by using
-- Integer internally.
-- - The internal structure is not exposed to avoid the construction of
-- invalid values. Use epoch or a parser to construct values.
-- - The instance of Show is only meant for debugging purposes
-- and is subject to change.
--
data Date
-- | This type represents time instants during a day (00:00:00 -
-- 23:59:59.999..) with arbitrary precision (uses Integer
-- internally).
--
--
-- - The internal structure is not exposed to avoid the creation of
-- invalid values. Use midnight or a parser to construct
-- values.
-- - The instance of Show is only meant for debugging purposes
-- and is subject to change.
--
data Time
-- | A time representation based on a Date and the Time of
-- the day.
--
--
-- - The type uses multiprecision integers internally and is able to
-- represent any UTC date in the past and in the future with arbitrary
-- precision (apart from the time span within a leap second).
-- - The instances of IsString and Show are only meant
-- for debugging purposes and default to epoch in case of failure.
-- Don't rely on their behaviour!
--
data DateTime
DateTime :: Date -> Time -> DateTime
date :: DateTime -> Date
time :: DateTime -> Time
-- | This type is used to extend UTC time types by a local offset in
-- seconds (positive or negative).
--
-- Beware: A local offset is not a time zone. It is just a fix
-- period of time. In contrast to a time zone this does not take summer
-- or winter time into account.
data Local time
Local :: time -> Maybe Rational -> Local time
-- | The time to be interpreted as UTC+00:00 (Western
-- European Time)
utc :: Local time -> time
-- |
-- - Nothing The local offset is unknown (behaves like
-- Western European Time)
-- - Just 0 UTC+00:00 (Western European
-- Time)
-- - Just 3600 UTC+01:00 (Central European
-- Time)
--
offset :: Local time -> Maybe Rational
class Rfc3339Parser a
parseRfc3339 :: (Rfc3339Parser a, Monad m, IsDate t, IsTime t, Epoch t) => a -> m (Local t)
class Rfc3339Renderer a
renderRfc3339 :: (Rfc3339Renderer a, Monad m, IsDate t, IsTime t, Epoch t) => Local t -> m a