mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 08:54:25 +00:00
import json import path import time import proc -- found in std/ after the program's own files, so a program's own json.fch always wins. path: join, base, dir, ext, stem, parts, clean, is_abs. time: now, millis, sleep, date, local, format, days_in_month (clock_gettime, strftime through C import). proc: run, output (an error with the command's output when it fails), env, pid, cwd. json: parse (errors with line and column), stringify, pretty, new_*, get/at/set/push/has/names and str_or/int_or/float_or/bool_or; \u escapes with surrogate pairs. The C importer now leaves a plain (non-const) char * parameter a ptr[char], a buffer C writes into; only const char * is text going in. str(ptr) and str([]u8) are in the self-hosted compiler. boot.sh: 40 passed, 0 failed.
19 lines
788 B
Text
19 lines
788 B
Text
import time
|
|
import proc
|
|
|
|
fn main() -> ! {
|
|
d := time.date(86400 * 365 + 3661)
|
|
print(d.year, d.month, d.day, d.hour, d.minute, d.second, d.weekday, d.yearday)
|
|
print(time.days_in_month(2024, 2), time.days_in_month(2023, 2), time.days_in_month(1900, 2), time.days_in_month(2000, 2), time.days_in_month(2024, 4))
|
|
a := time.millis()
|
|
time.sleep(30)
|
|
waited := time.millis() - a
|
|
print(waited >= 25 && waited < 500)
|
|
print(time.now() > 1700000000, time.format(0, "%Y") == "1970" || time.format(0, "%Y") == "1969")
|
|
|
|
print((try proc.output("echo hello; echo world")).trim())
|
|
print(proc.run("exit 3"))
|
|
bad := proc.output("echo oops; exit 2") or err
|
|
print(bad)
|
|
print(proc.env("FINCH_SURELY_NOT_SET", "fallback"), proc.pid() > 0, proc.cwd().len > 0)
|
|
}
|