// Time_t.cxx #include "dataset_util/Time.h" #include using std::string; using std::cout; using std::endl; void msg(string txt) { cout << "--- "; cout << txt; cout << " ---" << endl; } int Time_t() { msg("Invalid"); Time bad; cout << bad << endl; assert( ! bad.is_valid() ); msg("Now"); Time now = Time::now(); cout << now << endl; assert( now.is_valid() ); assert( now.to_string().size() ); msg("10 second interval"); TimeInterval dtim(10); cout << dtim << endl; assert( dtim.to_string().size() ); assert( dtim.seconds() == 10 ); msg("10 second negative interval"); TimeInterval dtimm(-10); cout << dtimm << endl; assert( dtimm.seconds() == -10 ); msg("Increment time"); Time later = now; later += dtim; cout << later << endl;; assert( later.unix_time() == now.unix_time()+10 ); msg("Decrement time"); later -= dtim; cout << later << endl; assert( later.unix_time() == now.unix_time() ); msg("Increment time interval"); TimeInterval dlater = dtim; dlater += dtim; assert( dlater.seconds() == 2*dtim.seconds() ); msg("Deccrement time interval"); dlater -= dtim; assert( dlater.seconds() == dtim.seconds() ); msg("long interval"); Time start = now; Time stop = now; TimeInterval dtim1(26*3600+3*60+4); cout << dtim1 << endl; stop += dtim1; TimeInterval dtim2(start, stop); cout << dtim2 << endl; assert( dtim1.seconds() == dtim2.seconds() ); return 0; } #ifdef CTEST_MAIN int main() { return Time_t(); } #endif