{-# OPTIONS -Wall -Werror #-}-- #hidemoduleData.Time.LocalTime.TimeOfDay(-- * Time of dayTimeOfDay(..),midnight,midday,utcToLocalTimeOfDay,localToUTCTimeOfDay,timeToTimeOfDay,timeOfDayToTime,dayFractionToTimeOfDay,timeOfDayToDayFraction)whereimportData.Time.LocalTime.TimeZoneimportData.Time.Calendar.PrivateimportData.Time.ClockimportData.Fixed-- | Time of day as represented in hour, minute and second (with picoseconds), typically used to express local time of day.dataTimeOfDay=TimeOfDay{-- | range 0 - 23todHour::Int,-- | range 0 - 59todMin::Int,-- | Note that 0 <= todSec < 61, accomodating leap seconds.-- Any local minute may have a leap second, since leap seconds happen in all zones simultaneouslytodSec::Pico}deriving(Eq,Ord)-- | Hour zeromidnight::TimeOfDaymidnight=TimeOfDay000-- | Hour twelvemidday::TimeOfDaymidday=TimeOfDay1200instanceShowTimeOfDaywhereshow(TimeOfDayhms)=(show2h)++":"++(show2m)++":"++(show2Fixeds)-- | Convert a ToD in UTC to a ToD in some timezone, together with a day adjustment.utcToLocalTimeOfDay::TimeZone->TimeOfDay->(Integer,TimeOfDay)utcToLocalTimeOfDayzone(TimeOfDayhms)=(fromIntegral(divh'24),TimeOfDay(modh'24)(modm'60)s)wherem'=m+timeZoneMinuteszoneh'=h+(divm'60)-- | Convert a ToD in some timezone to a ToD in UTC, together with a day adjustment.localToUTCTimeOfDay::TimeZone->TimeOfDay->(Integer,TimeOfDay)localToUTCTimeOfDayzone=utcToLocalTimeOfDay(minutesToTimeZone(negate(timeZoneMinuteszone)))posixDayLength::DiffTimeposixDayLength=fromInteger86400-- | Get a TimeOfDay given a time since midnight.-- Time more than 24h will be converted to leap-seconds.timeToTimeOfDay::DiffTime->TimeOfDaytimeToTimeOfDaydt|dt>=posixDayLength=TimeOfDay2359(60+(realToFrac(dt-posixDayLength)))timeToTimeOfDaydt=TimeOfDay(fromIntegerh)(fromIntegerm)swheres'=realToFracdts=mod's'60m'=div's'60m=mod'm'60h=div'm'60-- | Find out how much time since midnight a given TimeOfDay is.timeOfDayToTime::TimeOfDay->DiffTimetimeOfDayToTime(TimeOfDayhms)=((fromIntegralh)*60+(fromIntegralm))*60+(realToFracs)-- | Get a TimeOfDay given the fraction of a day since midnight.dayFractionToTimeOfDay::Rational->TimeOfDaydayFractionToTimeOfDaydf=timeToTimeOfDay(realToFrac(df*86400))-- | Get the fraction of a day since midnight given a TimeOfDay.timeOfDayToDayFraction::TimeOfDay->RationaltimeOfDayToDayFractiontod=realToFrac(timeOfDayToTimetod/posixDayLength)