#
Convert Slots to POSIX Time
The time in Plutus is described in POSIX time (the number of milliseconds that have elapsed since 1 January 1970 00:00:00.000). But the time in Plutus Playground is described in "slots". Each slot is 1000 milliseconds starting at 29 July 2020 9:44:51.000.
Slot 0 (the first slot) ends at 29 July 2020 9:44:51.999 (1596059091999).
Slot 1 ends at 29 July 2020 9:44:52.999 (1596059092999).
And so on.
If you need to calculate the POSIX time at the end of a specific slot, there is
a function in Plutus that will convert slots to POSIX time called
slotToEndPOSIXTime
. It takes two parameters:
SlotConfig
: A datatype to configure the length (ms) of one slot and the beginning of the first slotSlot
: The number of slots to show the time for
SlotConfig
for Plutus Playground is a defined standard.
You can find out what (for example) 10 slots past the start time of Plutus Playground's standard config is with this function.
Change into the plutus-apps
directory
cd plutus-apps
Start a Nix shell
nix-shell
Change into the Plutus Pioneer Program's week 1 directory
cd plutus-pioneer-program/code/week01
Start the REPL
cabal repl
In the REPL, import the following modules
import Data.Default
import Ledger.TimeSlot
Now you can use the function to determine the POSIX time for the end of 10 slots.
slotToEndPOSIXTime def 10
The corresponding POSIX time is shown:
POSIXTime {getPOSIXTime = 1596059101999}
Some arbitrary conversions are: