Documentation
¶
Overview ¶
Package time exposes Go's time.Time / time.Duration helpers as a Rumo standard-library module.
Time values are represented at the script/VM level as a *vm.Map whose values are bound *vm.BuiltinFunction methods (year, month, format, ...) plus two hidden sentinel keys, "__unix_nano" (*vm.Int) and "__zone" (*vm.String), that allow the package's freestanding helpers to losslessly rehydrate the original time.Time. BuiltinFunctions already participate in bytecode encoding, so this representation round-trips through compile / load without requiring a dedicated VM-level Object type.
Index ¶
Constants ¶
const ( TimeKeyUnixNano = "__unix_nano" TimeKeyZone = "__zone" TimeKeyZero = "__zero" )
Sentinel keys used to identify a Rumo-side time value and recover its underlying time.Time without information loss. Exported so that out-of-package helpers (e.g. vm/require) can construct an equal shape.
Variables ¶
var Module = module.NewBuiltin(). Const("second", int64(time.Second)). Const("minute", int64(time.Minute)). Const("hour", int64(time.Hour)). Const("day", int64(24*time.Hour)). Const("week", int64(7*24*time.Hour)). Const("millisecond", int64(time.Millisecond)). Const("microsecond", int64(time.Microsecond)). Const("nanosecond", int64(time.Nanosecond)). Func("Time(x) (t time) constructs a time instance from x (time-compatible value)", timeCtorFn). Func("is_time(x) (b bool) reports whether x is a time value", isTimeFn). Func("sleep(d int) sleeps for d nanoseconds (cancellable via context)", sleepFn). Func("parse_duration(s string) (d int) parses a Go duration string", parseDurationFn). Func("since(t time) (d int) returns time.Since(t) in nanoseconds", sinceFn). Func("until(t time) (d int) returns time.Until(t) in nanoseconds", untilFn). Func("duration_hours(d int) (h float) returns d as floating-point hours", durationFloatFn(time.Duration.Hours)). Func("duration_minutes(d int) (m float) returns d as floating-point minutes", durationFloatFn(time.Duration.Minutes)). Func("duration_nanoseconds(d int) (n int) returns d as nanoseconds", func(d int64) int64 { return time.Duration(d).Nanoseconds() }). Func("duration_seconds(d int) (s float) returns d as floating-point seconds", durationFloatFn(time.Duration.Seconds)). Func("duration_string(d int) (s string) returns d as a human-readable string", durationStringFn). Func("month_string(m int) (s string) returns the English name of month m [1-12]", monthStringFn). Func("date(year int, month int, day int, hour int, min int, sec int, nsec int) (t time)", dateFn). Func("now() (t time) returns the current local time", nowFn). Func("parse(layout string, value string) (t time) parses a formatted time string", parseFn). Func("unix(sec int, nsec int) (t time) returns the local Time corresponding to the given Unix time", unixFn). Func("add(t time, d int) (t time) returns t + d", addFn). Func("sub(t time, u time) (d int) returns t - u in nanoseconds", subFn). Func("add_date(t time, years int, months int, days int) (t time)", addDateFn). Func("after(t time, u time) (b bool) reports whether t is after u", afterFn). Func("before(t time, u time) (b bool) reports whether t is before u", beforeFn). Func("time_year(t time) (y int)", timeAccessorInt(func(t time.Time) int64 { return int64(t.Year()) })). Func("time_month(t time) (m int)", timeAccessorInt(func(t time.Time) int64 { return int64(t.Month()) })). Func("time_day(t time) (d int)", timeAccessorInt(func(t time.Time) int64 { return int64(t.Day()) })). Func("time_hour(t time) (h int)", timeAccessorInt(func(t time.Time) int64 { return int64(t.Hour()) })). Func("time_minute(t time) (m int)", timeAccessorInt(func(t time.Time) int64 { return int64(t.Minute()) })). Func("time_second(t time) (s int)", timeAccessorInt(func(t time.Time) int64 { return int64(t.Second()) })). Func("time_nanosecond(t time) (n int)", timeAccessorInt(func(t time.Time) int64 { return int64(t.Nanosecond()) })). Func("time_unix(t time) (s int)", timeAccessorInt(func(t time.Time) int64 { return t.Unix() })). Func("time_unix_nano(t time) (n int)", timeAccessorInt(func(t time.Time) int64 { return t.UnixNano() })). Func("time_format(t time, layout string) (s string)", timeFormatFn). Func("is_zero(t time) (b bool)", isZeroFn). Func("to_local(t time) (t time)", toLocalFn). Func("to_utc(t time) (t time)", toUtcFn). Func("time_location(t time) (s string)", timeLocationFn). Func("time_string(t time) (s string)", timeStringFn)
Module is the registered "time" builtin module.
Functions ¶
func TimeObject ¶
TimeObject returns the canonical Rumo representation of a Go time.Time.
The returned Map carries:
- the bound accessor methods (year, month, day, hour, minute, second, nanosecond, unix, unix_nano, string, location, is_zero, format),
- and the two hidden sentinel keys (TimeKeyUnixNano, TimeKeyZone) used by ToGoTime to recover the original value.
Types ¶
This section is empty.