sigildocs

(sigil time)

(sigil time) - Time and Date Library

Time and date operations including timestamps, high-resolution timing, and date/time formatting.

Current Time

(import (sigil time))

(current-second)              ; => 1705330200.123
(format-datetime (current-second))  ; => "2025-01-15 14:30:00"

Component Access

(let ((now (current-second)))
  (time-year now)    ; => 2025
  (time-month now)   ; => 1
  (time-day now)     ; => 15
  (time-hour now)    ; => 14
  (time-minute now)  ; => 30
  (time-second now)) ; => 0

Timing

(with-timing "my-operation"
  (lambda () (heavy-computation)))
; prints: my-operation: 0.523 seconds

Exports

Get current time as seconds since Unix epoch.

Returns a real number with fractional seconds.

(current-second)  ; => 1705330200.123456
current-jiffyprocedure

Get current time in jiffies (high-resolution timer).

Use with jiffies-per-second to compute elapsed time.

(current-jiffy)  ; => 123456789

Get the number of jiffies per second.

(jiffies-per-second)  ; => 1000000000 (nanosecond precision)
time->listprocedure

Convert a timestamp to a list of components.

Returns (second minute hour day month year weekday yearday dst?).

list->timeprocedure

Convert a list of time components to a timestamp.

time-secondprocedure

Get the seconds (0-59) from a timestamp.

time-minuteprocedure

Get the minutes (0-59) from a timestamp.

time-hourprocedure

Get the hour (0-23) from a timestamp.

time-dayprocedure

Get the day of month (1-31) from a timestamp.

time-monthprocedure

Get the month (1-12) from a timestamp.

time-yearprocedure

Get the year from a timestamp.

time-weekdayprocedure

Get the day of week (0=Sunday, 6=Saturday) from a timestamp.

time-yeardayprocedure

Get the day of year (1-366) from a timestamp.

time-dst?procedure

Check if daylight saving time is in effect for a timestamp.

Get the UTC offset in seconds for the local timezone.

(time-utc-offset)  ; => -18000 (EST = -5 hours)
sleepprocedure

Sleep for a given number of seconds (blocking).

This is a blocking sleep that pauses the entire thread. For async/cooperative sleep, use sleep from (sigil async).

(sleep 0.5)  ; sleep 500ms
(sleep 2)    ; sleep 2 seconds
time-elapsedprocedure

Measure elapsed time for evaluating a thunk.

Returns (values result elapsed-seconds).

(let-values (((result elapsed) (time-elapsed (lambda () (fib 30)))))
  (format "Result: ~a in ~a seconds" result elapsed))
with-timingprocedure

Execute thunk and print timing information.

Returns the result of the thunk.

(with-timing "compilation"
  (lambda () (compile-file "main.sgl")))
; prints: compilation: 0.523 seconds
format-timeprocedure

Format a timestamp as HH:MM:SS string.

Pass #t as second argument to format in UTC.

(format-time (current-second))       ; => "14:30:00"
(format-time (current-second) #t)    ; => "19:30:00" (UTC)
format-dateprocedure

Format a timestamp as YYYY-MM-DD string.

(format-date (current-second))  ; => "2025-01-15"

Format a timestamp as YYYY-MM-DD HH:MM:SS string.

(format-datetime (current-second))  ; => "2025-01-15 14:30:00"
pad-zeroprocedure

Pad number with leading zero if < 10. (pad-zero 5) -> "05" (pad-zero 15) -> "15"