I created a current time_point and converted it to structure tm and printed it's values. Now converted this tm structure to time_point. On comparing the first and second time_points, it is telling that they're different. But the values of structure are exactly same.
Can someone spot, where I'm doing wrong?
#include <iostream>
#include <ctime>
#include <chrono>
using namespace std;
using namespace std::chrono;
system_clock::time_point toTimePoint(struct tm tim)
{
return std::chrono::system_clock::from_time_t(mktime(&tim));
}
tm toTm(system_clock::time_point tp)
{
time_t tmt = system_clock::to_time_t(tp);
struct tm * tim = localtime(&tmt);
struct tm newTim(*tim);
cout << "Info: " << tim->tm_mday << "/" << tim->tm_mon << "/" << tim->tm_year << " " << tim->tm_hour << ":" << tim->tm_min << ":" << tim->tm_sec << endl;
cout << "Is Daylight saving: " << tim->tm_isdst << " wday: " << tim->tm_wday << " yday: " << tim->tm_yday << endl;
return newTim;
}
int _tmain(int argc, _TCHAR* argv[])
{
system_clock::time_point tp = system_clock::now();
struct tm tmstruct = toTm(tp);
system_clock::time_point newtp = toTimePoint(tmstruct);
cout << "Time comparison: " << (tp == newtp) << endl;
toTm(newtp);
}
Output:
Info: 8/4/115 16:26:20 Is Daylight saving: 0 wday: 5 yday: 127
Time comparison: 0
Info: 8/4/115 16:26:20 Is Daylight saving: 0 wday: 5 yday: 127