1
0
Fork 0
forked from fun/fun

Added some date/time basics. (0.19.0)

This commit is contained in:
Johannes Findeisen 2025-10-04 00:49:05 +02:00
commit 63edf97aba
11 changed files with 284 additions and 1 deletions

32
lib/utils/datetime.fun Normal file
View file

@ -0,0 +1,32 @@
// Date/time utilities abstraction for the Fun stdlib.
// Minimal version to validate syntax.
/*
* Date/time utilities abstraction for the Fun stdlib.
* Provides a convenient class-based API over VM date/time opcodes.
*
* Methods:
* - now_ms() -> current wall clock ms since Unix epoch
* - mono_ms() -> monotonic clock ms (for measuring intervals)
* - format(ms, fmt) -> format an epoch-ms timestamp using strftime format
* - iso_now() -> ISO-8601 like local timestamp (YYYY-MM-DDTHH:MM:SS)
*/
class DateTime()
// Current wall-clock time in milliseconds since Unix epoch
fun now_ms(this)
return time_now_ms()
// Monotonic clock in milliseconds
fun mono_ms(this)
return clock_mono_ms()
// Format an epoch-ms timestamp with a strftime() format string
fun format(this, ms, fmt)
// ensure argument order and types are okay
return date_format(to_number(ms), to_string(fmt))
// Convenience: ISO-like current datetime string (local time)
fun iso_now(this)
ms = time_now_ms()
return date_format(ms, "%Y-%m-%dT%H:%M:%S")