cheatah
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 .purr
4// program that exercises EVERY public function in stdlib/datetime/datetime.hpp
5// (timestamp, now, utcnow, today, format, year, month, day, hour, minute,
6// second, weekday), compiles it with purrc into a loadable module, runs it
7// under the cheatah runtime (TZ=UTC), and asserts the exact stdout.
8//
9// The current-time functions (timestamp/now/utcnow/today) are
10// non-deterministic, so the program prints DETERMINISTIC PROPERTIES (sign /
11// string length). The component getters and `format` use the calendar in local
12// time, so they are pinned to a FIXED epoch (0.0 = 1970-01-01 00:00:00 UTC) and
13// 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) and
15// the per-function compile-run tests (tests/purrc/datetime_cr_test.cpp).
16#include "e2e_harness.hpp"
18TEST(StdlibE2E, Datetime) {
19 e2e::expect_e2e("datetime_sys", R"PURR(import io
20import datetime
22# Current-time functions are non-deterministic; assert stable properties.
23io.print(datetime.timestamp() > 0.0)
24io.print(len(datetime.now()) == 19)
25io.print(len(datetime.utcnow()) == 20)
26io.print(len(datetime.today()) == 10)
28# Fixed epoch (0.0 = 1970-01-01 00:00:00 UTC) under TZ=UTC is fully deterministic.
29io.print(datetime.format(0.0, "%Y-%m-%d %H:%M:%S"))
30io.print(datetime.year(0.0), datetime.month(0.0), datetime.day(0.0))
31io.print(datetime.hour(0.0), datetime.minute(0.0), datetime.second(0.0))
32io.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 ");