Pages - Menu

標籤

AWS (1) bash (1) Boost (2) C (2) CMake (2) Concurrency_Programming (3) CPP (37) Database (2) DNS (1) Docker (4) Docker-Compose (1) ELK (1) emacs (4) gcp (1) gdrive (1) git (1) gitbash (2) gitlab (1) kvm (4) Linux (5) MT4 (4) MT5 (4) Multicast (2) MySQL (2) Nijatrader8 (1) OpenCV (1) Python (4) QT5 (1) R (1) rdp (3) screenshot (1) ssh (3) Tabnine (1) TCP (1) TensorFlow (1) Tools (12) Ubuntu_1904 (11) Ubuntu_20_04 (5) UDP (1) VS2010 (1) VS2015 (1) VS2019 (1) WebServer (1) Win10 (1) winmerge (1) WSL (1) xrdp (1)

搜尋此網誌

2020年4月30日星期四

A class that handle time in a rough way for Linux

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

沒有留言:

發佈留言