ClickHouse/src/IO/parseDateTimeBestEffort.h

68 lines
2.5 KiB
C++
Raw Normal View History

2020-10-10 18:37:02 +00:00
#pragma once
#include <stddef.h>
#include <time.h>
#include <Core/Types.h>
class DateLUTImpl;
namespace DB
{
class ReadBuffer;
2018-02-12 00:55:46 +00:00
/** https://xkcd.com/1179/
*
* The existence of this function is an example of bad practice
* and contradicts our development principles.
*
* This function will recognize the following patterns:
*
* NNNNNNNNNN - 9..10 digits is a unix timestamp
*
* YYYYMMDDhhmmss - 14 numbers is always interpreted this way
*
* YYYYMMDD - 8 digits in a row
2018-02-12 00:55:46 +00:00
* YYYY*MM*DD - or with any delimiter after first 4-digit year component and after month.
*
* DD/MM/YY
* DD/MM/YYYY - when '/' separator is used, these are the only possible forms
* Note that American style is not supported.
*
* hh:mm:ss - when ':' separator is used, it is always time
* hh:mm - it can be specified without seconds
*
* YYYY - 4 digits is always year
*
* YYYYMM - 6 digits is a year, month if year was not already read
* hhmmss - 6 digits is a time if year was already read
*
* .nnnnnnn - any number of digits after point is fractional part of second, if it is not YYYY.MM.DD or DD.MM.YYYY
*
* T - means that time will follow
*
* Z - means zero UTC offset
*
* +hhmm
* +hh:mm
* +hh
* -... - time zone offset
*
* single whitespace can be used as a separator
*
* AM/PM - AM means: subtract 12 hours if a value is 12 and PM means: add 12 hours if a value is less than 12.
*
2018-02-12 00:55:46 +00:00
* Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec - allowed to specify month
* Mon/Tue/Wed/Thu/Fri/Sat/Sun - simply ignored.
*/
void parseDateTimeBestEffort(time_t & res, ReadBuffer & in, const DateLUTImpl & local_time_zone, const DateLUTImpl & utc_time_zone);
bool tryParseDateTimeBestEffort(time_t & res, ReadBuffer & in, const DateLUTImpl & local_time_zone, const DateLUTImpl & utc_time_zone);
void parseDateTimeBestEffortUS(time_t & res, ReadBuffer & in, const DateLUTImpl & local_time_zone, const DateLUTImpl & utc_time_zone);
bool tryParseDateTimeBestEffortUS(time_t & res, ReadBuffer & in, const DateLUTImpl & local_time_zone, const DateLUTImpl & utc_time_zone);
void parseDateTime64BestEffort(DateTime64 & res, UInt32 scale, ReadBuffer & in, const DateLUTImpl & local_time_zone, const DateLUTImpl & utc_time_zone);
Extended range of DateTime64 to years 1925 - 2238 The Year 1925 is a starting point because most of the timezones switched to saner (mostly 15-minutes based) offsets somewhere during 1924 or before. And that significantly simplifies implementation. 2238 is to simplify arithmetics for sanitizing LUT index access; there are less than 0x1ffff days from 1925. * Extended DateLUTImpl internal LUT to 0x1ffff items, some of which represent negative (pre-1970) time values. As a collateral benefit, Date now correctly supports dates up to 2149 (instead of 2106). * Added a new strong typedef ExtendedDayNum, which represents dates pre-1970 and post 2149. * Functions that used to return DayNum now return ExtendedDayNum. * Refactored DateLUTImpl to untie DayNum from the dual role of being a value and an index (due to negative time). Index is now a different type LUTIndex with explicit conversion functions from DatNum, time_t, and ExtendedDayNum. * Updated DateLUTImpl to properly support values close to epoch start (1970-01-01 00:00), including negative ones. * Reduced resolution of DateLUTImpl::Values::time_at_offset_change to multiple of 15-minutes to allow storing 64-bits of time_t in DateLUTImpl::Value while keeping same size. * Minor performance updates to DateLUTImpl when building month LUT by skipping non-start-of-month days. * Fixed extractTimeZoneFromFunctionArguments to work correctly with DateTime64. * New unit-tests and stateless integration tests for both DateTime and DateTime64.
2020-04-17 13:26:44 +00:00
void parseDateTime64BestEffortUS(DateTime64 & res, UInt32 scale, ReadBuffer & in, const DateLUTImpl & local_time_zone, const DateLUTImpl & utc_time_zone);
bool tryParseDateTime64BestEffort(DateTime64 & res, UInt32 scale, ReadBuffer & in, const DateLUTImpl & local_time_zone, const DateLUTImpl & utc_time_zone);
}