///|
/// A length of time of 0 to 65535 milliseconds. Each wait of the server is shorter
/// than one minute. `UInt16` has no other values, so the constructor cannot fail, and
/// each function that takes a time limit can have it.
priv struct Duration {
value : UInt16
}
///|
/// A number of milliseconds.
fn Duration::Duration(millis : UInt16) -> Duration {
{ value: millis, }
}
///|
/// The time from `now` to `end`, both in milliseconds of `@async.now`. It is 0 when
/// `end` is in the past, and the longest duration when `end` is too far away.
fn Duration::between(now : Int64, end : Int64) -> Duration {
{ value: (end - now).clamp(min=0L, max=65535L).to_int().to_uint16(), }
}
///|
/// The number of milliseconds.
fn Duration::millis(self : Duration) -> Int32 {
self.value.to_int()
}
///|
/// The time that is the duration after `start`, in milliseconds of `@async.now`.
fn Duration::after(self : Duration, start : Int64) -> Int64 {
start + self.millis().to_int64()
}
///|
/// The time for people, such as `10 seconds` and `0.3 seconds`.
fn Duration::to_text(self : Duration) -> String {
"\{self.millis().to_double() / 1000} seconds"
}