Proposal: Time / Date / DateTime standard library (Go-inspired) — clocks, durations, offline progress #9
Labels
No labels
area:ci
area:docs
area:input
area:net
area:rendering
area:repo
area:stdlib
area:tooling
area:types
cleanup
dx
priority:high
priority:low
priority:medium
proposal
status:in-progress
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: workshopsoft/ludic#9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A built-in
Time/Date/DateTimelibrary — wall-clock time, calendardates, durations, and formatting/parsing — modeled on Go's excellent
timepackage but trimmed to what games actually need.
Proposal #2 already lists
Timeas part of the namespaced stdlib; this issue isthe detailed design + implementation for the calendar/clock half (frame timing
lives with the game loop).
Why it matters for game devs
ready at 18:00", offline progress.
5.minutes).Proposed API (illustrative)
Three types:
DateTime(instant),Date(calendar day),Duration(span).Helpers:
now,since,add,diff,format,parse, component getters(
year/month/day/hour/…),Duration.hours/minutes/seconds/frames.Considerations
Time.now()is non-deterministic input — keep it OUT ofsimulation that must replay; provide a simulated clock the game controls for
deterministic/lockstep gameplay (ties into networking #6-era work).
database in v1 (call it out as a follow-up).
Scope / acceptance
DateTime,Date,Durationtypes + core ops above.format/parsewith a small, documented pattern set.Related: #2 (stdlib namespacing), error handling (parse can fail).
Landed the calendar/clock core in
1a2c6ec(pushed to main).Implemented as plain-i32 integer epochs (no new type, no floating point — the "integer epochs to avoid drift" note), so everything is deterministic and bit-identical across platforms:
seconds/minutes/hours/days+as_seconds/as_minutes/as_hours/as_days. Since a duration is just anint,Duration.minutes(5) + Duration.seconds(30)andaway > Duration.hours(3)work with the ordinary operators.new/year/month/day/weekday/is_leap/days_in_month/to_epoch/add_days/diff_days.Time.now):from/date/add/year/month/day/weekday/hour/minute/second.The civil↔epoch conversions are Howard Hinnant's public-domain proleptic-Gregorian algorithms, in pure i32 IR. New
selfhost/emit_datetime.ludic; docs (3 sections + 28 method pages +time-since), inventory and LSP hover in sync; a registered test verifies component math. All suites green (26 self-host / 45 regression / 29 tools); C-free bootstrap fixpoint holds.Still open for a follow-up:
format/parse(needs a pattern-string runtime routine), a game-controlled simulated clock for deterministic/lockstep use, and timezones. v1 is UTC-only with no leap seconds and, on the i32 epoch, valid through 2038 — leaving this issue open to track those.Completed in
b5455cd(builds on the core in1a2c6ec), all on main. Every acceptance item is now delivered:DateTime.format(dt, pattern)/DateTime.parse(text, pattern)over the tokensYYYY YY MM DD HH mm ss(other characters pass through). The pattern is a string literal, expanded at compile time;parsereturns-1on a non-digit where one is expected, so malformed input is detectable.Clock.now/set/advance/reset, backed by a@L_clockglobal that never reads the wall clock, so gameplay readingClock.now()is deterministic and replay-safe.Time.now/Time.sinceremain the (non-deterministic) wall-clock path.examples/offline_rewards.ludic(the "you were away N hours" flow, asserted in the regression suite) plus doc pages for Duration/Date/DateTime/Clock andtime-since.selfhost/tests/datetime.ludic(component math) anddatetime2.ludic(format/parse round-trip, parse failure, clock).All suites green (27 self-host / 46 regression / 29 tools); C-free bootstrap fixpoint holds;
check.py(366 symbols),check-impl.py(218 ns-methods) andvalidate.pypass.v1 scope note (as flagged in the proposal): UTC-only, no leap seconds, and on the i32 epoch valid through 2038 — a tz database and a 64-bit epoch are natural future work but out of scope here. Closing as done.