Timestamps

Timestamps are provided by the BasicTimePackage (excluded when using a raw Engine) via the timestamp function.

Timestamps are not available under no_time or no_std.

The Rust type of a timestamp is std::time::Instant (instant::Instant in WASM builds).

type_of() a timestamp returns "timestamp".

Built-in Functions

The following methods (defined in the BasicTimePackage but excluded when using a raw Engine) operate on timestamps.

FunctionParameter(s)Description
elapsed method and propertynonereturns the number of seconds since the timestamp
+ operatornumber of seconds to addreturns a new timestamp with a specified number of seconds added
+= operatornumber of seconds to addadds a specified number of seconds to the timestamp
- operatornumber of seconds to subtractreturns a new timestamp with a specified number of seconds subtracted
-= operatornumber of seconds to subtractsubtracts a specified number of seconds from the timestamp
- operator
  1. later timestamp
  2. earlier timestamp
returns the number of seconds between the two timestamps

The following methods are defined in the LanguageCorePackage but excluded when using a raw Engine.

FunctionNot available underParameter(s)Description
sleepno_stdnumber of seconds to sleepblocks the current thread for a specified number of seconds

Examples

let now = timestamp();

// Do some lengthy operation...

if now.elapsed > 30.0 {
    print("takes too long (over 30 seconds)!")
}