1 {-# OPTIONS -fno-warn-orphans #-}
3 module Data

.Time

.LocalTime

.Internal

.LocalTime

9 -- converting UTC and UT1 times to LocalTime
16 import Control

.DeepSeq

18 import Data

.Time

.Calendar

.Days

19 import Data

.Time

.Calendar

.Gregorian

20 import Data

.Time

.Clock

.Internal

.NominalDiffTime

21 import Data

.Time

.Clock

.Internal

.UTCDiff

22 import Data

.Time

.Clock

.Internal

.UTCTime

23 import Data

.Time

.Clock

.Internal

.UniversalTime

24 import Data

.Time

.LocalTime

.Internal

.TimeOfDay

25 import Data

.Time

.LocalTime

.Internal

.TimeZone

27 -- | A simple day and time aggregate, where the day is of the specified parameter,
28 -- and the time is a TimeOfDay.
29 -- Conversion of this (as local civil time) to UTC depends on the time zone.
30 -- Conversion of this (as local mean time) to UT1 depends on the longitude.
31 data LocalTime

= LocalTime

33 , localTimeOfDay

:: TimeOfDay

34 } deriving (Eq

, Ord

, Data

, Typeable

)
36 instance NFData LocalTime

where
37 rnf

(LocalTime d t

) = rnf d `

seq` rnf t `

seq`

()
39 instance Show LocalTime

where
40 show (LocalTime d t

) = (showGregorian d

) ++ " " ++ (show t

)
42 -- | addLocalTime a b = a + b
43 addLocalTime

:: NominalDiffTime

-> LocalTime

-> LocalTime

44 addLocalTime x

= utcToLocalTime utc

. addUTCTime x

. localTimeToUTC utc

46 -- | diffLocalTime a b = a - b
47 diffLocalTime

:: LocalTime

-> LocalTime

-> NominalDiffTime

48 diffLocalTime a b

= diffUTCTime

(localTimeToUTC utc a

) (localTimeToUTC utc b

)
50 -- | Get the local time of a UTC time in a time zone.
51 utcToLocalTime

:: TimeZone

-> UTCTime

-> LocalTime

52 utcToLocalTime tz

(UTCTime day dt

) = LocalTime

(addDays i day

) tod

54 (i

, tod

) = utcToLocalTimeOfDay tz

(timeToTimeOfDay dt

)
56 -- | Get the UTC time of a local time in a time zone.
57 localTimeToUTC

:: TimeZone

-> LocalTime

-> UTCTime

58 localTimeToUTC tz

(LocalTime day tod

) = UTCTime

(addDays i day

) (timeOfDayToTime todUTC

)
60 (i

, todUTC

) = localToUTCTimeOfDay tz tod

62 -- | Get the local time of a UT1 time on a particular meridian (in degrees, positive is East).
63 ut1ToLocalTime

:: Rational -> UniversalTime

-> LocalTime

64 ut1ToLocalTime long

(ModJulianDate date

) =
65 LocalTime

(ModifiedJulianDay localMJD

) (dayFractionToTimeOfDay localToDOffset

)
67 localTime

= date

+ long

/ 360 :: Rational
68 localMJD

= floor localTime

69 localToDOffset

= localTime

- (fromIntegral localMJD

)
71 -- | Get the UT1 time of a local time on a particular meridian (in degrees, positive is East).
72 localTimeToUT1

:: Rational -> LocalTime

-> UniversalTime

73 localTimeToUT1 long

(LocalTime

(ModifiedJulianDay localMJD

) tod

) =
74 ModJulianDate

((fromIntegral localMJD

) + (timeOfDayToDayFraction tod

) - (long

/ 360))
77 instance Show UniversalTime

where
78 show t

= show (ut1ToLocalTime

0 t

)