Time Module

Why This Matters

Time functions are used for retries, delays, scheduling checks, timestamps, and logging context.

Import

import std.time.*;

Functions

  • Time.now(format: String): String
  • Time.unix(): Integer
  • Time.sleep(ms: Integer): None

1. Current Time String

import std.io.*;
import std.time.*;

function main(): None {
    now_default: String = Time.now("");
    now_iso_like: String = Time.now("%Y-%m-%d %H:%M:%S");
    println("default={now_default}");
    println("custom={now_iso_like}");
    return None;
}

Time.now("") uses default %H:%M:%S format.

2. Unix Timestamp

import std.io.*;
import std.time.*;

function main(): None {
    ts: Integer = Time.unix();
    println("unix={ts}");
    return None;
}

3. Sleep / Delay

import std.time.*;
import std.io.*;

function main(): None {
    println("waiting...");
    Time.sleep(250);
    println("done");
    return None;
}

Validation Rule

Negative sleep values are invalid. If statically known negative, compiler rejects during check; otherwise runtime path errors.

Effect Note

Time.* calls participate in effect checks and require thread capability. See Effects.

Common Mistakes

  • using sleep as synchronization substitute for real signaling
  • assuming formatted Time.now output is stable across all locales/environments
  • passing unvalidated timeout values from user input

Example In Repo

Built and maintained by TheRemyyy. Arden is open source under Apache 2.0 and published at theremyyy.dev.