(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)) ; => 0Timing
(with-timing "my-operation"
(lambda () (heavy-computation)))
; prints: my-operation: 0.523 secondsExports
current-secondprocedureGet current time as seconds since Unix epoch.
Returns a real number with fractional seconds.
(current-second) ; => 1705330200.123456current-jiffyprocedureGet current time in jiffies (high-resolution timer).
Use with jiffies-per-second to compute elapsed time.
(current-jiffy) ; => 123456789jiffies-per-secondprocedureGet the number of jiffies per second.
(jiffies-per-second) ; => 1000000000 (nanosecond precision)time->listprocedureConvert a timestamp to a list of components.
Returns (second minute hour day month year weekday yearday dst?).
list->timeprocedureConvert a list of time components to a timestamp.
time-secondprocedureGet the seconds (0-59) from a timestamp.
time-minuteprocedureGet the minutes (0-59) from a timestamp.
time-hourprocedureGet the hour (0-23) from a timestamp.
time-dayprocedureGet the day of month (1-31) from a timestamp.
time-monthprocedureGet the month (1-12) from a timestamp.
time-yearprocedureGet the year from a timestamp.
time-weekdayprocedureGet the day of week (0=Sunday, 6=Saturday) from a timestamp.
time-yeardayprocedureGet the day of year (1-366) from a timestamp.
time-dst?procedureCheck if daylight saving time is in effect for a timestamp.
time-utc-offsetprocedureGet the UTC offset in seconds for the local timezone.
(time-utc-offset) ; => -18000 (EST = -5 hours)sleepprocedureSleep 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 secondstime-elapsedprocedureMeasure 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-timingprocedureExecute thunk and print timing information.
Returns the result of the thunk.
(with-timing "compilation"
(lambda () (compile-file "main.sgl")))
; prints: compilation: 0.523 secondsformat-timeprocedureFormat 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-dateprocedureFormat a timestamp as YYYY-MM-DD string.
(format-date (current-second)) ; => "2025-01-15"format-datetimeprocedureFormat a timestamp as YYYY-MM-DD HH:MM:SS string.
(format-datetime (current-second)) ; => "2025-01-15 14:30:00"pad-zeroprocedurePad number with leading zero if < 10. (pad-zero 5) -> "05" (pad-zero 15) -> "15"