(ctx: Context)
| 13 | }; |
| 14 | |
| 15 | pub fn create_time_module(ctx: Context) -> ModuleKind { |
| 16 | let name = ctx.intern_static("std.time"); |
| 17 | |
| 18 | let exports = [ |
| 19 | // Constants |
| 20 | ("UNIX_EPOCH", Value::Number(0.0)), |
| 21 | // Core time functions |
| 22 | ("now", Value::NativeFunction(NativeFn(time_now))), |
| 23 | ( |
| 24 | "unix_timestamp", |
| 25 | Value::NativeFunction(NativeFn(time_unix_timestamp)), |
| 26 | ), |
| 27 | ("sleep", Value::NativeFunction(NativeFn(time_sleep))), |
| 28 | // Time conversion functions |
| 29 | ("to_utc", Value::NativeFunction(NativeFn(time_to_utc))), |
| 30 | ("to_local", Value::NativeFunction(NativeFn(time_to_local))), |
| 31 | ( |
| 32 | "format_datetime", |
| 33 | Value::NativeFunction(NativeFn(time_format_datetime)), |
| 34 | ), |
| 35 | ( |
| 36 | "parse_datetime", |
| 37 | Value::NativeFunction(NativeFn(time_parse_datetime)), |
| 38 | ), |
| 39 | // Duration functions |
| 40 | ("seconds", Value::NativeFunction(NativeFn(time_seconds))), |
| 41 | ("minutes", Value::NativeFunction(NativeFn(time_minutes))), |
| 42 | ("hours", Value::NativeFunction(NativeFn(time_hours))), |
| 43 | ("days", Value::NativeFunction(NativeFn(time_days))), |
| 44 | ] |
| 45 | .into_iter() |
| 46 | .map(|(name, f)| (ctx.intern_static(name), f)) |
| 47 | .collect(); |
| 48 | |
| 49 | ModuleKind::Native { name, exports } |
| 50 | } |
| 51 | |
| 52 | /// Returns the current time as Unix timestamp in seconds with fractional part |
| 53 | fn time_now<'gc>(_state: &mut State<'gc>, _args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> { |
no test coverage detected