MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / number_to_datetime

Function number_to_datetime

sql-common/my_time.c:1409–1490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1407*/
1408
1409longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
1410 ulonglong flags, int *was_cut)
1411{
1412 long part1,part2;
1413
1414 *was_cut= 0;
1415 memset(time_res, 0, sizeof(*time_res));
1416 time_res->time_type=MYSQL_TIMESTAMP_DATE;
1417
1418 if (nr == LL(0) || nr >= LL(10000101000000))
1419 {
1420 time_res->time_type=MYSQL_TIMESTAMP_DATETIME;
1421 if (nr > 99999999999999LL) /* 9999-99-99 99:99:99 */
1422 {
1423 *was_cut= MYSQL_TIME_WARN_OUT_OF_RANGE;
1424 return LL(-1);
1425 }
1426 goto ok;
1427 }
1428 if (nr < 101)
1429 goto err;
1430 if (nr <= (YY_PART_YEAR-1)*10000L+1231L)
1431 {
1432 nr= (nr+20000000L)*1000000L; /* YYMMDD, year: 2000-2069 */
1433 goto ok;
1434 }
1435 if (nr < (YY_PART_YEAR)*10000L+101L)
1436 goto err;
1437 if (nr <= 991231L)
1438 {
1439 nr= (nr+19000000L)*1000000L; /* YYMMDD, year: 1970-1999 */
1440 goto ok;
1441 }
1442 /*
1443 Though officially we support DATE values from 1000-01-01 only, one can
1444 easily insert a value like 1-1-1. So, for consistency reasons such dates
1445 are allowed when TIME_FUZZY_DATE is set.
1446 */
1447 if (nr < 10000101L && !(flags & TIME_FUZZY_DATE))
1448 goto err;
1449 if (nr <= 99991231L)
1450 {
1451 nr= nr*1000000L;
1452 goto ok;
1453 }
1454 if (nr < 101000000L)
1455 goto err;
1456
1457 time_res->time_type=MYSQL_TIMESTAMP_DATETIME;
1458
1459 if (nr <= (YY_PART_YEAR-1)*LL(10000000000)+LL(1231235959))
1460 {
1461 nr= nr+LL(20000000000000); /* YYMMDDHHMMSS, 2000-2069 */
1462 goto ok;
1463 }
1464 if (nr < YY_PART_YEAR*LL(10000000000)+ LL(101000000))
1465 goto err;
1466 if (nr <= LL(991231235959))

Callers 3

number_to_timeFunction · 0.85
lldiv_t_to_datetimeFunction · 0.85

Calls 2

check_datetime_rangeFunction · 0.85
check_dateFunction · 0.85

Tested by

no test coverage detected