Removed deprecated date and time functions [#METR-13554].

This commit is contained in:
Alexey Milovidov 2014-11-14 23:55:23 +03:00
parent 37746b8e96
commit 8f076b8ac4
4 changed files with 68 additions and 14 deletions

View File

@ -1,5 +1,5 @@
#include <DB/IO/ReadHelpers.h>
#include <DB/Storages/MergeTree/ActiveDataPartSet.h>
#include <Yandex/time2str.h>
#include <mysqlxx/DateTime.h>
@ -12,7 +12,7 @@ int main(int argc, char ** argv)
std::string name = DB::ActiveDataPartSet::getPartName(date, date, 0, 0, 0);
std::cerr << name << '\n';
time_t time = OrderedIdentifier2Date(name);
time_t time = DateLUT::instance().YYYYMMDDToDate(DB::parse<UInt32>(name));
std::cerr << mysqlxx::DateTime(time) << '\n';
}

View File

@ -1,7 +1,34 @@
#include <iostream>
#include <cstring>
#include <Yandex/DateLUT.h>
#include <Yandex/time2str.h>
static std::string toString(time_t Value)
{
struct tm tm;
char buf[96];
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);
return buf;
}
static time_t orderedIdentifierToDate(unsigned value)
{
struct tm tm;
memset(&tm, 0, sizeof(tm));
tm.tm_year = value / 10000 - 1900;
tm.tm_mon = (value % 10000) / 100 - 1;
tm.tm_mday = value % 100;
tm.tm_isdst = -1;
return mktime(&tm);
}
void loop(time_t begin, time_t end, int step)
@ -9,8 +36,8 @@ void loop(time_t begin, time_t end, int step)
DateLUT & date_lut = DateLUT::instance();
for (time_t t = begin; t < end; t += step)
std::cout << Time2Sql(t)
<< ", " << Time2Sql(date_lut.toTimeInaccurate(t))
std::cout << toString(t)
<< ", " << toString(date_lut.toTimeInaccurate(t))
<< ", " << date_lut.toHourInaccurate(t)
<< std::endl;
}
@ -18,9 +45,9 @@ void loop(time_t begin, time_t end, int step)
int main(int argc, char ** argv)
{
loop(OrderedIdentifier2Date(20101031), OrderedIdentifier2Date(20101101), 15 * 60);
loop(OrderedIdentifier2Date(20100328), OrderedIdentifier2Date(20100330), 15 * 60);
loop(OrderedIdentifier2Date(20141020), OrderedIdentifier2Date(20141106), 15 * 60);
loop(orderedIdentifierToDate(20101031), orderedIdentifierToDate(20101101), 15 * 60);
loop(orderedIdentifierToDate(20100328), orderedIdentifierToDate(20100330), 15 * 60);
loop(orderedIdentifierToDate(20141020), orderedIdentifierToDate(20141106), 15 * 60);
return 0;
}

View File

@ -1,9 +1,36 @@
#include <iostream>
#include <cstring>
#include <Poco/Exception.h>
#include <Yandex/DateLUT.h>
#include <Yandex/time2str.h>
static std::string toString(time_t Value)
{
struct tm tm;
char buf[96];
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);
return buf;
}
static time_t orderedIdentifierToDate(unsigned value)
{
struct tm tm;
memset(&tm, 0, sizeof(tm));
tm.tm_year = value / 10000 - 1900;
tm.tm_mon = (value % 10000) / 100 - 1;
tm.tm_mday = value % 100;
tm.tm_isdst = -1;
return mktime(&tm);
}
void loop(time_t begin, time_t end, int step)
@ -15,8 +42,8 @@ void loop(time_t begin, time_t end, int step)
time_t t2 = date_lut.makeDateTime(date_lut.toYear(t), date_lut.toMonth(t), date_lut.toDayOfMonth(t),
date_lut.toHourInaccurate(t), date_lut.toMinute(t), date_lut.toSecond(t));
std::string s1 = Time2Sql(t);
std::string s2 = Time2Sql(t2);
std::string s1 = toString(t);
std::string s2 = toString(t2);
std::cerr << s1 << ", " << s2 << std::endl;
@ -28,8 +55,8 @@ void loop(time_t begin, time_t end, int step)
int main(int argc, char ** argv)
{
loop(OrderedIdentifier2Date(20101031), OrderedIdentifier2Date(20101101), 15 * 60);
loop(OrderedIdentifier2Date(20100328), OrderedIdentifier2Date(20100330), 15 * 60);
loop(orderedIdentifierToDate(20101031), orderedIdentifierToDate(20101101), 15 * 60);
loop(orderedIdentifierToDate(20100328), orderedIdentifierToDate(20100330), 15 * 60);
return 0;
}

View File

@ -178,7 +178,7 @@ public:
inline std::ostream & operator<< (std::ostream & ostr, const DateTime & datetime)
{
ostr << std::setfill('0') << std::setw(4) << datetime.year();
ostr << std::setfill('0') << std::setw(4) << datetime.year();
ostr << '-' << (datetime.month() / 10) << (datetime.month() % 10)
<< '-' << (datetime.day() / 10) << (datetime.day() % 10)