mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
DateLUT: added methods makeDayNum(), makeDate(), makeDateTime().
This commit is contained in:
parent
9e4585633a
commit
193cd7481d
@ -32,5 +32,13 @@ namespace Yandex
|
||||
|
||||
lut.push_back(values);
|
||||
}
|
||||
|
||||
/// Заполняем lookup таблицу для годов
|
||||
memset(years_lut, 0, DATE_LUT_YEARS * sizeof(years_lut[0]));
|
||||
for (size_t day = 0; day < lut.size() && lut[day].year < DATE_LUT_YEARS + 1900; ++day)
|
||||
{
|
||||
if (lut[day].month == 1 && lut[day].day_of_month == 1)
|
||||
years_lut[lut[day].year - 1900] = day;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
libs/libcommon/src/tests/date_lut3.cpp
Normal file
35
libs/libcommon/src/tests/date_lut3.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <Poco/Exception.h>
|
||||
|
||||
#include <Yandex/DateLUT.h>
|
||||
#include <Yandex/time2str.h>
|
||||
|
||||
|
||||
void loop(time_t begin, time_t end, int step)
|
||||
{
|
||||
Yandex::DateLUTSingleton & date_lut = Yandex::DateLUTSingleton::instance();
|
||||
|
||||
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.toHourInaccurate(t), date_lut.toMinute(t), date_lut.toSecond(t));
|
||||
|
||||
std::string s1 = Yandex::Time2Sql(t);
|
||||
std::string s2 = Yandex::Time2Sql(t2);
|
||||
|
||||
std::cerr << s1 << ", " << s2 << std::endl;
|
||||
|
||||
if (s1 != s2)
|
||||
throw Poco::Exception("Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
loop(Yandex::OrderedIdentifier2Date(20101031), Yandex::OrderedIdentifier2Date(20101101), 15 * 60);
|
||||
loop(Yandex::OrderedIdentifier2Date(20100328), Yandex::OrderedIdentifier2Date(20100330), 15 * 60);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user