Some checks are pending
docs / build-and-deploy (push) Waiting to run
Implement the calendar/clock half of #9 as plain-i32 integer epochs — no new type, no floating point (the issue's "integer epochs to avoid drift") — so every operation is deterministic and bit-identical on every platform: Duration — a span in whole seconds; seconds/minutes/hours/days build one, as_seconds/as_minutes/as_hours/as_days read it back. Because a duration is just an int, `+` and `>` work with no extra machinery (Duration.minutes(5) + Duration.seconds(30), away > Duration.hours(3)). Date — a civil day as days-since-1970 (UTC): new/year/month/day/weekday/ is_leap/days_in_month/to_epoch/add_days/diff_days. DateTime — an instant as seconds-since-1970 (UTC, matching Time.now): from/date/add/year/month/day/weekday/hour/minute/second. Time.since(past) = now - past, for offline-progress / "time away" checks. New selfhost/emit_datetime.ludic (is_/emit_ for the three namespaces, wired into emit_ns_call + the frag list). The two civil<->epoch conversions are Howard Hinnant's public-domain proleptic-Gregorian algorithms, emitted once per program as the @fn_days_from_civil / @fn_civil_from_days prelude and gated by g_uses_datert; days_in_month is next-month-day-0 (no lookup table). Time gains `since`. Docs (Duration/Date/DateTime sections, 28 method pages + time-since), inventory, and LSP hover kept in sync; a registered test checks component math against hand-computed values. Reseeded; C-free fixpoint holds; all suites green (26 self-host / 45 regression / 29 tools); check.py, check-impl.py and validate.py OK. format/parse, a game-controlled simulated clock, and timezones are tracked follow-ups; v1 is UTC-only and, on the i32 epoch, valid through 2038. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
2.2 KiB
Text
43 lines
2.2 KiB
Text
program T {
|
|
entry {
|
|
# Duration — spans in whole seconds
|
|
print(Duration.hours(3)) # 10800
|
|
print(Duration.minutes(5) + Duration.seconds(30)) # 330
|
|
print(Duration.days(2)) # 172800
|
|
print(Duration.as_hours(10800)) # 3
|
|
print(Duration.as_days(172800)) # 2
|
|
|
|
# Date — civil day as days-since-1970, round-trips both ways
|
|
print(Date.new(1970, 1, 1)) # 0
|
|
print(Date.new(2000, 1, 1)) # 10957
|
|
let d = Date.new(2026, 8, 30)
|
|
print(Date.year(d)) # 2026
|
|
print(Date.month(d)) # 8
|
|
print(Date.day(d)) # 30
|
|
print(Date.weekday(Date.new(1970, 1, 1))) # 4 (Thursday)
|
|
print(Date.weekday(Date.new(2000, 1, 1))) # 6 (Saturday)
|
|
print(Date.is_leap(2000)) # 1
|
|
print(Date.is_leap(1900)) # 0
|
|
print(Date.is_leap(2024)) # 1
|
|
print(Date.days_in_month(2024, 2)) # 29 (leap Feb)
|
|
print(Date.days_in_month(2023, 2)) # 28
|
|
print(Date.days_in_month(2026, 12)) # 31 (December rollover)
|
|
let feb = Date.add_days(Date.new(2026, 1, 1), 31)
|
|
print(Date.month(feb)) # 2
|
|
print(Date.day(feb)) # 1
|
|
print(Date.diff_days(Date.new(2026, 1, 1), Date.new(2025, 1, 1))) # 365
|
|
|
|
# DateTime — instant as seconds-since-1970
|
|
let t = DateTime.from(2000, 1, 1, 12, 30, 15)
|
|
print(t) # 946729815
|
|
print(DateTime.year(t)) # 2000
|
|
print(DateTime.month(t)) # 1
|
|
print(DateTime.day(t)) # 1
|
|
print(DateTime.hour(t)) # 12
|
|
print(DateTime.minute(t)) # 30
|
|
print(DateTime.second(t)) # 15
|
|
print(DateTime.weekday(t)) # 6
|
|
print(DateTime.date(t)) # 10957
|
|
print(DateTime.hour(DateTime.add(0, Duration.hours(1)))) # 1
|
|
}
|
|
}
|