Timestamps
LIGO features timestamps by means of the predefined type timestamp
,
as Michelson does. Bakers making the block (including the transaction
in a block) are responsible for providing the given current timestamp
for the contract.
Now
You can obtain the starting time of the current block using the
function Mavryk.get_now
from the standard library. This timestamp
does not change during the execution of the contract. Please be aware
that it is up to the baker to set the current timestamp value.
When testing your code, the LIGO CLI option
--now
allows you to control whatMavryk.get_now
returns.
Arithmetic
In LIGO, timestamps can be added to integers, allowing you to set time constraints on your smart contracts. Consider the following scenarios.
Incrementing
Decrementing
Subtracting
Timestamps can be subtracted, that means, we can use minus (-
)
between two timestamps:
Notice that the result of such subtraction is an int
, which describes the difference in seconds between the two timestamps.
Comparing
You can compare timestamps using the same comparison operators applying to numerical value.