Source
tests/purrc/datetime_sys_test.cpp
1
// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).2
// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.3
// System-level test for the cheatah `datetime` module: a single cohesive .purr4
// program that exercises EVERY public function in stdlib/datetime/datetime.hpp5
// (timestamp, now, utcnow, today, format, year, month, day, hour, minute,6
// second, weekday), compiles it with purrc into a loadable module, runs it7
// under the cheatah runtime (TZ=UTC), and asserts the exact stdout.8
//9
// The current-time functions (timestamp/now/utcnow/today) are10
// non-deterministic, so the program prints DETERMINISTIC PROPERTIES (sign /11
// string length). The component getters and `format` use the calendar in local12
// time, so they are pinned to a FIXED epoch (0.0 = 1970-01-01 00:00:00 UTC) and13
// run under TZ=UTC (the 4th expect_e2e arg) to be fully deterministic.14
// Complements the in-process unit tests (stdlib/tests/datetime_test.cpp) and15
// the per-function compile-run tests (tests/purrc/datetime_cr_test.cpp).16
#include "e2e_harness.hpp"18
TEST(StdlibE2E, Datetime) {19
e2e::expect_e2e("datetime_sys", R"PURR(import io20
import datetime22
# Current-time functions are non-deterministic; assert stable properties.23
io.print(datetime.timestamp() > 0.0)24
io.print(len(datetime.now()) == 19)25
io.print(len(datetime.utcnow()) == 20)26
io.print(len(datetime.today()) == 10)28
# Fixed epoch (0.0 = 1970-01-01 00:00:00 UTC) under TZ=UTC is fully deterministic.29
io.print(datetime.format(0.0, "%Y-%m-%d %H:%M:%S"))30
io.print(datetime.year(0.0), datetime.month(0.0), datetime.day(0.0))31
io.print(datetime.hour(0.0), datetime.minute(0.0), datetime.second(0.0))32
io.print(datetime.weekday(0.0))33
)PURR",34
"True\n"35
"True\n"36
"True\n"37
"True\n"38
"1970-01-01 00:00:00\n"39
"1970 1 1\n"40
"0 0 0\n"41
"3\n",42
"TZ=UTC ");43
}