Getting Current Time#
Get the current date/time as a time value:
Get current time into now.
a time called now is current time.
Time Properties#
Access components of a time value using the 's property syntax:
| Property | Description | Type |
|---|---|---|
hour | Hour of day (0-23) | Number |
minute | Minute (0-59) | Number |
second | Second (0-59) | Number |
day | Day of month (1-31) | Number |
month | Month (1-12) | Number |
year | Year (e.g., 2026) | Number |
unix | Unix timestamp (seconds since epoch) | Number |
Example:
Get current time into now.
Print "Current time: ".
Print the now's hour.
Print ":".
Print the now's minute.
Print ":".
Print the now's second.
Print "Date: ".
Print the now's year.
Print "-".
Print the now's month.
Print "-".
Print the now's day.
Inline Time Access#
Access current time properties directly without storing:
Print "It is currently hour ".
Print current time's hour.
Print " of the day.".
Sleep / Wait#
Pause program execution for a specified duration:
Wait 1 second.
Wait 2 seconds.
Wait 500 milliseconds.
Sleep for 3 seconds.
Syntax variations:
Wait <N> second./Wait <N> seconds.Wait <N> millisecond./Wait <N> milliseconds.Sleep for <N> seconds.Sleep for <N> milliseconds.
Timers#
Timers are stopwatches for measuring durations. They track start time, end time, and elapsed duration.
Creating a Timer#
Create a timer called 'job timer'.
a timer called benchmark.
Starting and Stopping#
Start the 'job timer'.
(... do work ...)
Stop the 'job timer'.
Alternative spellings:
Start/BeginStop/Finish
These four words are contextual, not reserved. They open a timer statement only when a name operand follows — Start the t., stop t. — and everywhere else they are ordinary identifiers, so a number called stop is 0. compiles, and a program may define and call its own zero-argument start. function. (End is not a Stop spelling: end belongs to the exit family of keywords and remains reserved.)
Timer Properties#
| Property | Description | Type |
|---|---|---|
duration | Total duration (requires cast) | Duration |
elapsed | Elapsed time while running (requires cast) | Duration |
start time | When timer was started (unix timestamp) | Number |
end time | When timer was stopped (unix timestamp) | Number |
running | Whether timer is currently running | Boolean |
Getting Duration#
Use in to cast duration to a specific unit:
Print the 'job timer''s duration in seconds.
Print the 'job timer''s duration in milliseconds.
Print the 'job timer''s elapsed in seconds.
Complete Timer Example#
(Measure job duration)
Print "Starting job...".
Create a timer called 'job timer'.
Start the 'job timer'.
(... do work ...)
Wait 1 second.
Print "Seconds elapsed so far: ".
Print the 'job timer''s elapsed in seconds.
Wait 500 milliseconds.
Stop the 'job timer'.
Print "Finished the job in: ".
Print the 'job timer''s duration in seconds.
Print " seconds".
(Access raw timestamps)
Print "Started at unix time: ".
Print the 'job timer''s start time.
Print "Stopped at unix time: ".
Print the 'job timer''s end time.
Formatted Time Output#
Combine time properties with the zero-pad format specifier (see Format Specifiers) for formatted output. A time property can be read directly inside a format slot:
Get current time into now.
Print "{now's hour:02}:{now's minute:02}:{now's second:02}".
(Prints: 09:05:03)
Or, if you want the parts as named values first:
Get current time into now.
a text called h is "{now's hour:02}".
a text called m is "{now's minute:02}".
a text called s is "{now's second:02}".
Print "{h}:{m}:{s}".
(Prints: 09:05:03)