Validates that the operand represents a Timestamp
and returns the bigint
representing its absolute time value.
During the transition explained in theTimeMath
comment,
absValue
will also accept a bigint which it then just returns.
An absolute time + a relative time gives a new absolute time.
A relative time (i.e., a duration) + another relative time gives a new relative time.
The difference between two absolute times is a relative time. If abs1 > abs2 the difference would be negative, so this method returns a zero relative time instead.
Coerces to a RelativeTime if possible. If a brand is provided, ensure it matches and return a RelativeTime labeled with that brand.
Coerces to a TimestampRecord if possible, else throws. If the value has a brand, ensure it matches. Return a Timestamp labeled with that brand.
Compares two absolute times. This comparison function is compatible
with JavaScript's Array.prototype.sort
and so can be used to sort an
array of absolute times. The result is -1, 0, or 1 indicating whether
the first argument is less than, equal, or greater than the second.
Compares two relative times. This comparison function is compatible
with JavaScript's Array.prototype.sort
and so can be used to sort an
array of relative times. The result is -1, 0, or 1 indicating whether
the first argument is less than, equal, or greater than the second.
Does it represent a zero relative time, i.e., the difference of an absolute time with itself? (We choose not to define a similar isAbsZero, even though we could, because it is much less likely to be meaningful.)
An absolute time modulo a relative time is a relative time. For example, 20:17 on July 20, 1969 modulo 1 day is just 20:17, a relative time that can be added to the beginning of any day.
A relative time modulo a relative time is a relative time. For example, 3.5 hours modulo an hour is 30 minutes.
Validates that the operand represents a RelativeTime
and returns the
bigint representing its relative time value.
During the transition explained in theTimeMath
comment,
relValue
will also accept a bigint which it then just returns.
The difference between two absolute times is a relative time. If abs1 > abs2 the difference would be negative, so this method throws instead.
An absolute time - a relative time gives a new absolute time
The difference between two relative times.
TimeMath supports simple arithmetic on typed Time values, enforcing that values are combined in type-compatible ways. You can add 3 minutes to 3pm, or 5 minutes to a half hour, but it makes no sense to add 3pm and 5pm. Subtracting two Timestamps does produce a useful difference.
The brands prevent you from accidentally combining time values from different TimerServices. Some chains track time in blocks, others follow wall clock time, some do both. Every local computer has its own unique notion of wall clock time. Even when these clocks are talking about the same thing (UTC), they can all drift in different ways. Using the correct brands lets you be precise about which particular source of time you mean, preventing confusion or attacks when the clocks diverge. Thus it is an error to e.g. use a time you got from chain A to schedule an event on chain B.
The basic types are
RelativeTimeRecord
(durations) andTimestampRecord
. The numeric values can be extracted from the typed values, but it's usually better to maintain values as their canonical typed form so these operations can be applied.