#include #include #include #include "JSystem/JDate.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * Test program for JDate. */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Test program for JDate."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } { vector buffer = { "2020-01-26 20:24:48.123456789Z", // ROOT TTimeStamp::AsString("c") "1000-01-10T10:10:10Z", "10000110T101010Z" }; for (string word : buffer) { DEBUG("Date and time " << word << ' ' << JDateAndTime::isISO8601(word) << endl); ASSERT(JDateAndTime::isISO8601(word), "Date and time <" << word << ">"); ASSERT(JDateAndTime(word).isUTC(), "Date and time <" << word << ">"); } } { vector buffer = { "1000-01-10T10:10:10+00:00", "1000-01-10T10:10:10-00:00", "1000-01-10T10:10:10+0000", "1000-01-10T10:10:10-0000", "1000-01-10T10:10:10+00", "1000-01-10T10:10:10-00" }; for (string word : buffer) { DEBUG("Date and time " << word << ' ' << JDateAndTime::isISO8601(word) << endl); ASSERT(JDateAndTime::isISO8601(word), "Date and time <" << word << ">"); ASSERT(!JDateAndTime(word).isUTC(), "Date and time <" << word << ">"); } } { const JDateAndTime t1; const JDateAndTime t2(t1.toString()); DEBUG("t1 " << t1.getTime() << ' ' << t1.toString() << endl); DEBUG("t2 " << t2.getTime() << ' ' << t2.toString() << endl); { double x = t1.getElapsedTime(t2); ASSERT(x == 0.0, "elapsed time " << x); } { JDateAndTime t3(t2); time_t ts = 100; t3.add(ts); double x = t1.getElapsedTime(t3); ASSERT(x == +ts, "add " << noshowpos << ts << " -> elapsed time " << showpos << x); } { JDateAndTime t3(t2); time_t ts = 100; t3.sub(ts); double x = t1.getElapsedTime(t3); ASSERT(x == -ts, "sub " << noshowpos << ts << " -> elapsed time " << showpos << x); } } { const JDateAndTime t1(123456789, true); const JDateAndTime t2(t1.toString()); DEBUG("t1 " << t1.getTime() << ' ' << t1.toString() << endl); DEBUG("t2 " << t2.getTime() << ' ' << t2.toString() << endl); { double x = t1.getElapsedTime(t2); ASSERT(x == 0.0, "elapsed time " << x); } } return 0; }