Is there a built-in way to get timestamps in Sway?
10 Likes
I also have this problem
1 Like
The standard library has you covered when it comes to timestamps!
the std::block module has height(), timestamp() and timestamp_of_block(block_height: u64) functions you can use.
Reference:
2 Likes
The timestamp returned from the std-lib is a TAI64 format timestamp, which is different than unix. Adding 86400 to the timestamp will add 1 day.
Abstractions over common time periods should be provided by the std-lib imo
2 Likes
This is a good idea, @mohammadfawaz thoughts on this being introduced to either sway-libs or std-lib?
I.e. time unites: 1 day, 1 hour, 1 second etc.
3 Likes
Good idea indeed. Created an issue here: Consider generating more readable timestamps in the standard library · Issue #3945 · FuelLabs/sway · GitHub
2 Likes