0 | module IotaTime.Duration
7 | record DurationRep where
8 | constructor MkDuration
9 | storedNanoseconds : Integer
14 | Duration = DurationRep
18 | left == right = left.storedNanoseconds == right.storedNanoseconds
22 | compare left right = compare left.storedNanoseconds right.storedNanoseconds
26 | show value = "fromNanoseconds " ++ show value.storedNanoseconds
30 | durationFromNanoseconds : Integer -> Duration
31 | durationFromNanoseconds = MkDuration
35 | fromNanoseconds : Integer -> Duration
36 | fromNanoseconds = durationFromNanoseconds
40 | durationFromMicroseconds : Integer -> Duration
41 | durationFromMicroseconds value = MkDuration (value * 1000)
45 | fromMicroseconds : Integer -> Duration
46 | fromMicroseconds = durationFromMicroseconds
50 | durationFromMilliseconds : Integer -> Duration
51 | durationFromMilliseconds value = MkDuration (value * 1000000)
55 | fromMilliseconds : Integer -> Duration
56 | fromMilliseconds = durationFromMilliseconds
60 | durationFromSeconds : Integer -> Duration
61 | durationFromSeconds value = MkDuration (value * 1000000000)
65 | fromSeconds : Integer -> Duration
66 | fromSeconds = durationFromSeconds
70 | durationFromMinutes : Integer -> Duration
71 | durationFromMinutes value = durationFromSeconds (value * 60)
75 | fromMinutes : Integer -> Duration
76 | fromMinutes = durationFromMinutes
80 | durationFromHours : Integer -> Duration
81 | durationFromHours value = durationFromMinutes (value * 60)
85 | fromHours : Integer -> Duration
86 | fromHours = durationFromHours
90 | durationFromStandardDays : Integer -> Duration
91 | durationFromStandardDays value = durationFromHours (value * 24)
95 | fromStandardDays : Integer -> Duration
96 | fromStandardDays = durationFromStandardDays
100 | durationFromStandardWeeks : Integer -> Duration
101 | durationFromStandardWeeks value = durationFromStandardDays (value * 7)
105 | fromStandardWeeks : Integer -> Duration
106 | fromStandardWeeks = durationFromStandardWeeks
110 | toDurationNanoseconds : Duration -> Integer
111 | toDurationNanoseconds = storedNanoseconds
115 | toMicroseconds : Duration -> Integer
116 | toMicroseconds value = toDurationNanoseconds value `div` 1000
120 | toMilliseconds : Duration -> Integer
121 | toMilliseconds value = toMicroseconds value `div` 1000
125 | toSeconds : Duration -> Integer
126 | toSeconds value = toMilliseconds value `div` 1000
130 | toMinutes : Duration -> Integer
131 | toMinutes value = toSeconds value `div` 60
135 | toHours : Duration -> Integer
136 | toHours value = toMinutes value `div` 60
140 | toStandardDays : Duration -> Integer
141 | toStandardDays value = toHours value `div` 24
145 | toStandardWeeks : Duration -> Integer
146 | toStandardWeeks value = toStandardDays value `div` 7
150 | zeroDuration : Duration
151 | zeroDuration = MkDuration 0
155 | addDurations : Duration -> Duration -> Duration
156 | addDurations left right =
157 | MkDuration (left.storedNanoseconds + right.storedNanoseconds)
161 | add : Duration -> Duration -> Duration
166 | subtractDurations : Duration -> Duration -> Duration
167 | subtractDurations left right =
168 | MkDuration (left.storedNanoseconds - right.storedNanoseconds)
172 | minus : Duration -> Duration -> Duration
173 | minus = subtractDurations
177 | negateDuration : Duration -> Duration
178 | negateDuration value = MkDuration (negate value.storedNanoseconds)
182 | scaleDuration : Integer -> Duration -> Duration
183 | scaleDuration factor value = MkDuration (factor * value.storedNanoseconds)
187 | durationNanosecondsRoundTrip : (value : Integer) ->
188 | toDurationNanoseconds (fromNanoseconds value) = value
189 | durationNanosecondsRoundTrip value = Refl
193 | durationRoundTrip : (value : Duration) ->
194 | fromNanoseconds (toDurationNanoseconds value) = value
195 | durationRoundTrip (MkDuration value) = Refl