2011-01-21 21:38:02 +00:00
|
|
|
#include <iostream>
|
2014-11-14 20:55:23 +00:00
|
|
|
#include <cstring>
|
2011-01-21 21:38:02 +00:00
|
|
|
|
2011-03-03 17:22:19 +00:00
|
|
|
#include <Poco/Exception.h>
|
|
|
|
|
2015-09-29 19:19:54 +00:00
|
|
|
#include <common/DateLUT.h>
|
2014-11-14 20:55:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
static std::string toString(time_t Value)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
struct tm tm;
|
|
|
|
char buf[96];
|
2014-11-14 20:55:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
localtime_r(&Value, &tm);
|
|
|
|
snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d",
|
|
|
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
2014-11-14 20:55:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return buf;
|
2014-11-14 20:55:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static time_t orderedIdentifierToDate(unsigned value)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
struct tm tm;
|
2014-11-14 20:55:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
memset(&tm, 0, sizeof(tm));
|
2014-11-14 20:55:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
tm.tm_year = value / 10000 - 1900;
|
|
|
|
tm.tm_mon = (value % 10000) / 100 - 1;
|
|
|
|
tm.tm_mday = value % 100;
|
|
|
|
tm.tm_isdst = -1;
|
2014-11-14 20:55:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return mktime(&tm);
|
2014-11-14 20:55:23 +00:00
|
|
|
}
|
2011-01-21 21:38:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
void loop(time_t begin, time_t end, int step)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
const auto & date_lut = DateLUT::instance();
|
2017-03-31 16:00:30 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (time_t t = begin; t < end; t += step)
|
|
|
|
{
|
|
|
|
time_t t2 = date_lut.makeDateTime(date_lut.toYear(t), date_lut.toMonth(t), date_lut.toDayOfMonth(t),
|
|
|
|
date_lut.toHour(t), date_lut.toMinute(t), date_lut.toSecond(t));
|
2011-03-03 17:22:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string s1 = toString(t);
|
|
|
|
std::string s2 = toString(t2);
|
2017-03-31 16:00:30 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << s1 << ", " << s2 << std::endl;
|
2017-03-31 16:00:30 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (s1 != s2)
|
|
|
|
throw Poco::Exception("Test failed.");
|
|
|
|
}
|
2011-01-21 21:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-18 03:27:32 +00:00
|
|
|
int main(int, char **)
|
2011-01-21 21:38:02 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
loop(orderedIdentifierToDate(20101031), orderedIdentifierToDate(20101101), 15 * 60);
|
|
|
|
loop(orderedIdentifierToDate(20100328), orderedIdentifierToDate(20100330), 15 * 60);
|
2011-01-21 21:38:02 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return 0;
|
2011-01-21 21:38:02 +00:00
|
|
|
}
|