||| UTC
|||
||| UTC is time as measured by a clock, corrected to keep pace with the earth by adding or removing
||| occasional seconds, known as \"leap seconds\".
||| These corrections are not predictable and are announced with six month's notice.
||| No table of these corrections is provided, as any program compiled with it would become
||| out of date in six months.
|||
||| If you don't care about leap seconds, use 'UTCTime' and 'NominalDiffTime' for your clock calculations,
||| and you'll be fine.

module Data.Time.Clock.Internal.UTCTime

import Data.Time.Clock.Internal.DiffTime
import Data.Time.Calendar.Days

||| This is the simplest representation of UTC.
||| It consists of the day number, and a time offset from midnight.
||| Note that if a day has a leap second added to it, it will have 86401 seconds.
public export
record UTCTime where
  constructor MkUTCTime
  ||| utctDay the day
  utctDay : Day
  |||  utctDayTime the time from midnight, 0 <= t < 86401s (because of leap-seconds)
  utctDayTime : DiffTime

-- instance NFData UTCTime where
--     rnf (UTCTime d t) = rnf d `seq` rnf t `seq` ()

Eq UTCTime where
  (MkUTCTime da ta) == (MkUTCTime db tb) = (da == db) && (ta == tb)

Ord UTCTime where
  compare (MkUTCTime da ta) (MkUTCTime db tb) =
    case (compare da db) of
         EQ => compare ta tb
         cmp => cmp
