Skip to content

fastc-lang/fastc-core-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastc-core-time

Wall-clock time, epoch conversion, and ISO 8601 formatting for fastC.

Part of the fastc-core launch set. The implementation currently ships inside the fastC compiler's built-in prelude — every fastC v1.0 program already gets use time::* for free. This repository is the public home for the module's API and will become installable via fastc add github.com/Skelf-Research/fastc-core-time once stage 1.7's vendor-consumption flow completes the loop.

Surface

use time::now;             // (cap: ref(CapTimeRead)) -> i64 — epoch seconds
use time::now_ms;          // (cap: ref(CapTimeRead)) -> i64 — epoch milliseconds

use time::format_iso8601;  // (epoch_secs: i64) -> Str — RFC 3339 / ISO 8601
use time::parse_iso8601;   // (s: Str) -> opt(i64) — None on malformed input

use time::Duration;        // struct
use time::Duration::from_secs;    // (s: i64) -> Duration
use time::Duration::from_millis;  // (ms: i64) -> Duration

now wraps the prelude's time::now and is the canonical entry point for epoch seconds. now_ms returns the same instant at millisecond resolution. Both clamp negative system clocks to 0 so downstream i64 math is monotonic-ish even on broken hosts.

format_iso8601 emits the RFC 3339 profile of ISO 8601 (YYYY-MM-DDTHH:MM:SSZ, always UTC). parse_iso8601 accepts the same shape plus the common +HH:MM / -HH:MM offset forms and returns None rather than a default on any malformed byte.

Example

use time::now;
use time::format_iso8601;
use io::println;
use io::print_int;
use io::put_char;
use caps::time_read;

fn main() -> i32 {
    let t: i64 = now(&time_read);
    print_int(t);
    put_char(10);
    println(format_iso8601(t));
    return 0;
}

Capability policy

now and now_ms read the system clock and require a ref(CapTimeRead) token — wall-clock reads are a side channel the compiler treats as observable I/O. format_iso8601 and parse_iso8601 are pure: they take i64 / Str in and give Str / opt(i64) out with no ambient state, so no capability token is required.

Duration::from_secs and Duration::from_millis are pure constructors — value conversion only, no clock access.

Status

v0.1.0 — preview. API is final; the package becomes a true installable via fastc add once the consumption flow ships. Until then, the same API is available in every fastC v1.0 program via the built-in prelude.

License

MIT

About

Wall-clock time helpers for fastC. Part of the fastc-core six-month set.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors