mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 14:57:18 +00:00
60 lines
1.1 KiB
Plaintext
60 lines
1.1 KiB
Plaintext
// time.vr — date/time helpers (part of the VuurRaaf stdlib).
|
|
//
|
|
// import time
|
|
// println(time.format(time.now(), "YYYY-MM-DD HH:mm:ss"))
|
|
// println(time.format(time.now(), "YYYY-MM-DD"))
|
|
//
|
|
// Tokens follow the Moment.js style: YYYY (year), MM (month), DD (day),
|
|
// HH (24h hour), mm (minute), ss (second), plus literals like "-", ":".
|
|
// All values are Unix epoch seconds. `time.parse` accepts common ISO
|
|
// timestamps like "2026-08-25 14:03:22".
|
|
|
|
fn now() {
|
|
return now()
|
|
}
|
|
|
|
fn ms() {
|
|
return time_ms()
|
|
}
|
|
|
|
fn format(t, spec) {
|
|
return format_time(t, spec)
|
|
}
|
|
|
|
fn parse(s) {
|
|
return parse_time(s)
|
|
}
|
|
|
|
// date(t) formats just the calendar day: YYYY-MM-DD.
|
|
fn date(t) {
|
|
return format_time(t, "YYYY-MM-DD")
|
|
}
|
|
|
|
// clock(t) formats just the wall clock: HH:mm:ss.
|
|
fn clock(t) {
|
|
return format_time(t, "HH:mm:ss")
|
|
}
|
|
|
|
// weekday(t) returns the day of the week, e.g. "Mon", "Tue", ... "Sun".
|
|
fn weekday(t) {
|
|
return weekday(t)
|
|
}
|
|
|
|
// --- date arithmetic (all values are Unix epoch seconds) ---
|
|
|
|
fn add_seconds(t, n) {
|
|
return t + n
|
|
}
|
|
|
|
fn add_minutes(t, n) {
|
|
return t + n * 60
|
|
}
|
|
|
|
fn add_hours(t, n) {
|
|
return t + n * 3600
|
|
}
|
|
|
|
fn add_days(t, n) {
|
|
return t + n * 86400
|
|
}
|