-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Description
Add two new standard library modules for date/time operations and performance measurement.
std::datetime
Time and date utilities.
| Function | Signature | Description |
|---|---|---|
now_ms |
() -> int |
Current Unix timestamp in milliseconds |
now_s |
() -> int |
Current Unix timestamp in seconds |
year |
(timestamp_ms: int) -> int |
Extract year from timestamp |
month |
(timestamp_ms: int) -> int |
Extract month (1-12) |
day |
(timestamp_ms: int) -> int |
Extract day of month (1-31) |
hour |
(timestamp_ms: int) -> int |
Extract hour (0-23) |
minute |
(timestamp_ms: int) -> int |
Extract minute (0-59) |
second |
(timestamp_ms: int) -> int |
Extract second (0-59) |
day_of_week |
(timestamp_ms: int) -> int |
Day of week (0=Sun, 6=Sat) |
format_date |
(timestamp_ms: int, fmt: string) -> string |
Format timestamp to string |
use std::datetime::*;
fn main() {
var ts: int = now_ms();
println("Year: {}", year(ts));
println("Date: {}", format_date(ts, "YYYY-MM-DD"));
}
std::metrics
Performance measurement and benchmarking utilities.
| Function | Signature | Description |
|---|---|---|
perf_now |
() -> int |
High-resolution monotonic time in nanoseconds |
elapsed_ms |
(start_ns: int) -> int |
Milliseconds elapsed since start |
elapsed_us |
(start_ns: int) -> int |
Microseconds elapsed since start |
elapsed_ns |
(start_ns: int) -> int |
Nanoseconds elapsed since start |
use std::metrics::*;
fn main() {
var start: int = perf_now();
// ... work ...
println("Took {} ms", elapsed_ms(start));
}
Implementation
Follow the existing StdModuleFn pattern used by std::io, std::random, std::threads:
- Typechecker: Add
"datetime"and"metrics"entries inget_std_module_functions() - Runtime: Add
extern "C"functions innamlc/src/runtime/ - Codegen: Register symbols and add dispatch in
cranelift/mod.rs - Docs: Update
language-reference.mdwith new modules
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels