static void push_date_time(lua_State *l, const Time::DateTime &dt) { int year, month, day, hour, minute, second; dt.GetDateParts(&year, &month, &day); dt.GetTimeParts(&hour, &minute, &second); lua_newtable(l); pi_lua_settable(l, "year", year); pi_lua_settable(l, "month", month); pi_lua_settable(l, "day", day); pi_lua_settable(l, "hour", hour); pi_lua_settable(l, "minute", minute); pi_lua_settable(l, "second", second); pi_lua_settable(l, "timestamp", dt.ToGameTime()); }
void test_datetime() { const Time::DateTime EPOCH; std::cout << "Microsecond: " << std::setw(12) << Sint64(Time::Microsecond) << "\n"; std::cout << "Millisecond: " << std::setw(12) << Sint64(Time::Millisecond) << "\n"; std::cout << " Second: " << std::setw(12) << Sint64(Time::Second) << "\n"; std::cout << " Minute: " << std::setw(12) << Sint64(Time::Minute) << "\n"; std::cout << " Hour: " << std::setw(12) << Sint64(Time::Hour) << "\n"; std::cout << " Day: " << std::setw(12) << Sint64(Time::Day) << "\n"; std::cout << " Week: " << std::setw(12) << Sint64(Time::Week) << "\n"; std::cout << "epoch: " << EPOCH.ToStringISO8601() << "\n"; for (int i = -10; i <= 10; ++i) { const Time::DateTime t = EPOCH + TimeDelta(i, Time::Hour); std::cout << "epoch + " << i << " hours = " << t.ToStringISO8601() << "\n"; } for (int i = -10; i <= 10; ++i) { const Time::DateTime t = EPOCH + TimeDelta(i, Time::Day); std::cout << "epoch + " << i << " days = " << t.ToStringISO8601() << "\n"; } for (int i = 0; CHECK_AROUND_TIMES[i][3] != -1; ++i) { const int *x = CHECK_AROUND_TIMES[i]; check_datetime_round_trip(x[0],x[1],x[2], x[3],x[4],x[5], true); } Time::DateTime t = DateTime(1600,1,1, 0,0,0); std::cout << "Checking round trips for *many* timestamps...\n"; std::cout << " beginning at " << t.ToDateString() << " " << t.ToTimeString() << "\n"; std::cout << " (checking round-trip every 6 hours)\n"; for (int i = 0; i <= 4000000; ++i) { int year, month, day, hour, minute, second; t.GetDateParts(&year, &month, &day); t.GetTimeParts(&hour, &minute, &second); check_datetime_round_trip(year, month, day, hour, minute, second, false); t = t + TimeDelta(6, Time::Hour); } std::cout << " ending at " << t.ToDateString() << " " << t.ToTimeString() << "\n"; }