0 | module IotaTime.Clock
2 | import IotaTime.Instant
3 | import IotaTime.ZonedDateTime
10 | interface Clock clock where
11 | getCurrentInstant : clock -> IO Instant
15 | data SystemClock = MkSystemClock
18 | Clock SystemClock where
19 | getCurrentInstant MkSystemClock = now
23 | systemClock : SystemClock
24 | systemClock = MkSystemClock
28 | data FixedClock = MkFixedClock Instant
31 | Clock FixedClock where
32 | getCurrentInstant (MkFixedClock value) = pure value
36 | fixedClock : Instant -> FixedClock
37 | fixedClock = MkFixedClock
41 | record ZonedClock (calendar : Type) (clock : Type) where
42 | constructor MkZonedClock
43 | underlyingClock : clock
44 | clockZone : TimeZone
48 | zonedClock : {calendar : Type} -> clock -> TimeZone -> ZonedClock calendar clock
49 | zonedClock = MkZonedClock
53 | getCurrentZonedDateTime : {calendar : Type} -> {clock : Type} ->
54 | {auto cal : Calendar calendar} ->
55 | {auto rep : HasCalendarBridge
56 | (CalendarDate calendar @{cal})} ->
57 | Clock clock => ZonedClock calendar clock ->
58 | IO (Either CalendarConversionError
59 | (ZonedDateTime calendar @{cal}))
60 | getCurrentZonedDateTime value = do
61 | instant <- getCurrentInstant value.underlyingClock
62 | pure (IotaTime.ZonedDateTime.fromInstant instant value.clockZone)