fix and update test

This commit is contained in:
flynn 2022-10-04 13:36:28 +00:00
parent 86cb9f7034
commit e30297e599
5 changed files with 34 additions and 14 deletions

View File

@ -116,7 +116,7 @@ ReturnType parseDateTimeBestEffortImpl(
bool is_am = false; bool is_am = false;
bool is_pm = false; bool is_pm = false;
bool has_comma_after_date = false; bool has_comma_between_date_and_time = false;
auto read_alpha_month = [&month] (const auto & alpha) auto read_alpha_month = [&month] (const auto & alpha)
{ {
@ -139,10 +139,13 @@ ReturnType parseDateTimeBestEffortImpl(
while (!in.eof()) while (!in.eof())
{ {
if (year && month && day_of_month && *in.position() == ',') if ((year && !has_time) || (!year && has_time))
{ {
has_comma_after_date = true; if (*in.position() == ',')
++in.position(); {
has_comma_between_date_and_time = true;
++in.position();
}
} }
char digits[std::numeric_limits<UInt64>::digits10]; char digits[std::numeric_limits<UInt64>::digits10];
@ -561,7 +564,7 @@ ReturnType parseDateTimeBestEffortImpl(
} }
//// Date like '2022/03/04, ' should parse fail? //// Date like '2022/03/04, ' should parse fail?
if (has_comma_after_date && !has_time) if (has_comma_between_date_and_time && (!has_time || !year || !month || !day_of_month))
return on_error("Cannot read DateTime: unexpected word after Date", ErrorCodes::CANNOT_PARSE_DATETIME); return on_error("Cannot read DateTime: unexpected word after Date", ErrorCodes::CANNOT_PARSE_DATETIME);
/// If neither Date nor Time is parsed successfully, it should fail /// If neither Date nor Time is parsed successfully, it should fail

View File

@ -0,0 +1,10 @@
2017-12-01 18:31:44
2017-01-12 18:31:44
2017-12-01 18:31:44
2017-01-12 18:31:44
2017-12-01 18:31:44
2017-01-12 18:31:44
2015-12-31 18:31:44
2015-12-31 18:31:44
2015-12-31 18:31:44
2015-12-31 18:31:44

View File

@ -0,0 +1,16 @@
select parseDateTimeBestEffort('01/12/2017, 18:31:44');
select parseDateTimeBestEffortUS('01/12/2017, 18:31:44');
select parseDateTimeBestEffort('01/12/2017,18:31:44');
select parseDateTimeBestEffortUS('01/12/2017,18:31:44');
select parseDateTimeBestEffort('01/12/2017 , 18:31:44');
select parseDateTimeBestEffortUS('01/12/2017 ,18:31:44');
select parseDateTimeBestEffortUS('18:31:44, 31/12/2015');
select parseDateTimeBestEffortUS('18:31:44 , 31/12/2015');
select parseDateTimeBestEffort('18:31:44, 31/12/2015');
select parseDateTimeBestEffort('18:31:44 , 31/12/2015');
select parseDateTimeBestEffort('01/12/2017,'); -- { serverError CANNOT_PARSE_DATETIME }
select parseDateTimeBestEffortUS('18:31:44,,,, 31/12/2015'); -- { serverError CANNOT_PARSE_DATETIME }
select parseDateTimeBestEffortUS('18:31:44, 31/12/2015,'); -- { serverError CANNOT_PARSE_TEXT }
select parseDateTimeBestEffort('01/12/2017, 18:31:44,'); -- { serverError CANNOT_PARSE_TEXT }
select parseDateTimeBestEffort('01/12/2017, ,,,18:31:44'); -- { serverError CANNOT_PARSE_DATETIME }
select parseDateTimeBestEffort('18:31:44 ,,,,, 31/12/2015'); -- { serverError CANNOT_PARSE_DATETIME }

View File

@ -1,4 +0,0 @@
2017-12-01 18:31:44
2017-01-12 18:31:44
2017-12-01 18:31:44
2017-01-12 18:31:44

View File

@ -1,5 +0,0 @@
select parseDateTimeBestEffort('01/12/2017, 18:31:44');
select parseDateTimeBestEffortUS('01/12/2017, 18:31:44');
select parseDateTimeBestEffort('01/12/2017,18:31:44');
select parseDateTimeBestEffortUS('01/12/2017,18:31:44');
select parseDateTimeBestEffort('01/12/2017,'); -- { serverError CANNOT_PARSE_DATETIME}