Merge pull request #2827 from Z-snails/clock

export `{to,from}Nano` in `System.Clock`
This commit is contained in:
Zoe Stafford 2022-12-21 17:22:22 +00:00 committed by GitHub
commit 45fc038300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -232,6 +232,7 @@ clockTime clockType with (isClockMandatory clockType)
else pure Nothing
||| Convert the time in the given clock to nanoseconds.
public export
toNano : Clock type -> Integer
toNano (MkClock seconds nanoseconds) =
let scale = 1000000000
@ -240,6 +241,7 @@ toNano (MkClock seconds nanoseconds) =
||| Convert some time in nanoseconds to a `Clock` containing that time.
|||
||| @ n the time in nanoseconds
public export
fromNano : {type : ClockType} -> (n : Integer) -> Clock type
fromNano n =
let scale = 1000000000
@ -248,9 +250,11 @@ fromNano n =
in MkClock seconds nanoseconds
||| Compute difference between two clocks of the same type.
||| @ end the end time
||| @ start the start time
public export
timeDifference : Clock type -> Clock type -> Clock Duration
timeDifference clock duration = fromNano $ toNano clock - toNano duration
timeDifference end start = fromNano $ toNano end - toNano start
||| Add a duration to a clock value.
public export