Aim
This class is a simple handler for time. You can do time adding, comparing. It works on Linux. It can get current time in debug mode and normal mode. In a trading strategy backtesting process, you may use the debug mode to get a current time.
Source
#include <iostream> #include <thread> #include <chrono> #include "NLTimeUTC.h" // usage: ./NLTimeUTC void NormalUseCase() { std::cout << __FUNCTION__ << "-----------------" << std::endl; { NLTimeUTC time; std::cout << time.ToString() << std::endl; } std::this_thread::sleep_for(std::chrono::seconds(1)); { NLTimeUTC time; std::cout << time.ToString() << std::endl; } } void DebugUseCase_TickTick() { { NLTimeUTC time; std::cout << time.ToString() << std::endl; } if (TSCLOCK_IS_DEBUG()) TSCLOCK_ADD_SEC(1); else std::this_thread::sleep_for(std::chrono::seconds(1)); { NLTimeUTC time; std::cout << time.ToString() << std::endl; } } void DebugUseCase() { std::cout << std::endl; std::cout << __FUNCTION__ << "-----------------" << std::endl; std::cout << "Is debug: " << TSCLOCK_IS_DEBUG() << std::endl; DebugUseCase_TickTick(); TSCLOCK_SET_DEBUG(true); std::cout << "Is debug: " << TSCLOCK_IS_DEBUG() << std::endl; TSCLOCK_SET_CLOCK_DATE(2020, 3, 23, 3, 32, 40); DebugUseCase_TickTick(); } int main(int argc, char *argv[]) { NormalUseCase(); DebugUseCase(); return 0; }
Output
$ ./src/NLTimeUTC
NormalUseCase-----------------
2020-05-01 03:43:15
2020-05-01 03:43:16
DebugUseCase-----------------
Is debug: 0
2020-05-01 03:43:16
2020-05-01 03:43:17
Is debug: 1
2020-03-23 03:32:40
2020-03-23 03:32:41
沒有留言:
發佈留言