{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.HodaTime.OffsetDateTime
(
OffsetDateTime
,fromInstantWithOffset
,fromCalendarDateTimeWithOffset
)
where
import Data.HodaTime.Offset.Internal
import Data.HodaTime.Instant.Internal (Instant)
import Data.HodaTime.CalendarDateTime.Internal (CalendarDateTime, IsCalendarDateTime(..), Date)
import Data.HodaTime.ZonedDateTime.Internal (ZonedDateTime(..))
import Data.HodaTime.TimeZone.Internal (TimeZone(..), TZIdentifier(..), TransitionInfo, fixedOffsetZone)
newtype OffsetDateTime cal = OffsetDateTime (ZonedDateTime cal)
deriving instance Eq (Date cal) => Eq (OffsetDateTime cal)
deriving instance Show (Date cal) => Show (OffsetDateTime cal)
fromInstantWithOffset :: IsCalendarDateTime cal => Instant -> Offset -> OffsetDateTime cal
fromInstantWithOffset :: forall cal.
IsCalendarDateTime cal =>
Instant -> Offset -> OffsetDateTime cal
fromInstantWithOffset Instant
inst Offset
offset = ZonedDateTime cal -> OffsetDateTime cal
forall cal. ZonedDateTime cal -> OffsetDateTime cal
OffsetDateTime (ZonedDateTime cal -> OffsetDateTime cal)
-> ZonedDateTime cal -> OffsetDateTime cal
forall a b. (a -> b) -> a -> b
$ CalendarDateTime cal
-> TimeZone -> TransitionInfo -> ZonedDateTime cal
forall cal.
CalendarDateTime cal
-> TimeZone -> TransitionInfo -> ZonedDateTime cal
ZonedDateTime CalendarDateTime cal
cdt TimeZone
tz TransitionInfo
tInfo
where
(TimeZone
tz, TransitionInfo
tInfo) = Offset -> (TimeZone, TransitionInfo)
makeFixedTimeZone Offset
offset
cdt :: CalendarDateTime cal
cdt = Instant -> CalendarDateTime cal
forall cal.
IsCalendarDateTime cal =>
Instant -> CalendarDateTime cal
fromAdjustedInstant (Instant -> CalendarDateTime cal)
-> (Instant -> Instant) -> Instant -> CalendarDateTime cal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Offset -> Instant -> Instant
adjustInstant Offset
offset (Instant -> CalendarDateTime cal)
-> Instant -> CalendarDateTime cal
forall a b. (a -> b) -> a -> b
$ Instant
inst
fromCalendarDateTimeWithOffset :: CalendarDateTime cal -> Offset -> OffsetDateTime cal
fromCalendarDateTimeWithOffset :: forall cal. CalendarDateTime cal -> Offset -> OffsetDateTime cal
fromCalendarDateTimeWithOffset CalendarDateTime cal
cdt Offset
offset = ZonedDateTime cal -> OffsetDateTime cal
forall cal. ZonedDateTime cal -> OffsetDateTime cal
OffsetDateTime (ZonedDateTime cal -> OffsetDateTime cal)
-> ZonedDateTime cal -> OffsetDateTime cal
forall a b. (a -> b) -> a -> b
$ CalendarDateTime cal
-> TimeZone -> TransitionInfo -> ZonedDateTime cal
forall cal.
CalendarDateTime cal
-> TimeZone -> TransitionInfo -> ZonedDateTime cal
ZonedDateTime CalendarDateTime cal
cdt TimeZone
tz TransitionInfo
tInfo
where
(TimeZone
tz, TransitionInfo
tInfo) = Offset -> (TimeZone, TransitionInfo)
makeFixedTimeZone Offset
offset
makeFixedTimeZone :: Offset -> (TimeZone, TransitionInfo)
makeFixedTimeZone :: Offset -> (TimeZone, TransitionInfo)
makeFixedTimeZone Offset
offset = (TZIdentifier
-> UtcTransitionsMap -> CalDateTransitionsMap -> TimeZone
TimeZone (String -> TZIdentifier
Zone String
tzName) UtcTransitionsMap
utcM CalDateTransitionsMap
calDateM, TransitionInfo
tInfo)
where
tzName :: String
tzName = Offset -> String
toStringRep Offset
offset
(UtcTransitionsMap
utcM, CalDateTransitionsMap
calDateM, TransitionInfo
tInfo) = String
-> Offset
-> (UtcTransitionsMap, CalDateTransitionsMap, TransitionInfo)
fixedOffsetZone String
tzName Offset
offset