Merge pull request #22937 from Enmk/formatDateTime_toDateTime64_fixes

Fixes: formatDateTime and toDateTime64
This commit is contained in:
alexey-milovidov 2021-04-13 01:40:25 +03:00 committed by GitHub
commit ee9aaab4bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 2 deletions

View File

@ -480,7 +480,7 @@ public:
// since right now LUT does not support Int64-values and not format instructions for subsecond parts,
// treat DatTime64 values just as DateTime values by ignoring fractional and casting to UInt32.
const auto c = DecimalUtils::split(vec[i], scale);
instruction.perform(pos, static_cast<UInt32>(c.whole), time_zone);
instruction.perform(pos, static_cast<Int64>(c.whole), time_zone);
}
}
else

View File

@ -773,7 +773,8 @@ inline ReturnType readDateTimeTextImpl(DateTime64 & datetime64, UInt32 scale, Re
while (!buf.eof() && isNumericASCII(*buf.position()))
++buf.position();
}
else if (scale && (whole >= 1000000000LL * scale))
/// 9908870400 is time_t value for 2184-01-01 UTC (a bit over the last year supported by DateTime64)
else if (whole >= 9908870400LL)
{
/// Unix timestamp with subsecond precision, already scaled to integer.
/// For disambiguation we support only time since 2001-09-09 01:46:40 UTC and less than 30 000 years in future.

View File

@ -0,0 +1,27 @@
-- { echo }
SELECT formatDateTime(toDateTime64('1935-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
19
SELECT formatDateTime(toDateTime64('1969-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
19
SELECT formatDateTime(toDateTime64('1989-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
19
SELECT formatDateTime(toDateTime64('2019-09-16 19:20:12', 0, 'Europe/Moscow'), '%C');
20
SELECT formatDateTime(toDateTime64('2105-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
21
SELECT formatDateTime(toDateTime64('2205-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
22
-- non-zero scale
SELECT formatDateTime(toDateTime64('1935-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
19
SELECT formatDateTime(toDateTime64('1969-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
19
SELECT formatDateTime(toDateTime64('1989-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
19
SELECT formatDateTime(toDateTime64('2019-09-16 19:20:12', 0, 'Europe/Moscow'), '%C');
20
SELECT formatDateTime(toDateTime64('2105-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
21
SELECT formatDateTime(toDateTime64('2205-01-12 12:12:12', 6, 'Europe/Moscow'), '%C');
22

View File

@ -0,0 +1,16 @@
-- { echo }
SELECT formatDateTime(toDateTime64('1935-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('1969-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('1989-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2019-09-16 19:20:12', 0, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2105-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2205-12-12 12:12:12', 0, 'Europe/Moscow'), '%C');
-- non-zero scale
SELECT formatDateTime(toDateTime64('1935-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('1969-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('1989-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2019-09-16 19:20:12', 0, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2105-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2205-01-12 12:12:12', 6, 'Europe/Moscow'), '%C');

View File

@ -0,0 +1,10 @@
-- { echo }
SELECT toDateTime64('2205-12-12 12:12:12', 0, 'UTC');
2205-12-12 12:12:12
SELECT toDateTime64('2205-12-12 12:12:12', 0, 'Europe/Moscow');
2205-12-12 12:12:12
SELECT toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow');
2205-12-12 12:12:12.000000
SELECT toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow');
2205-12-12 12:12:12.000000

View File

@ -0,0 +1,7 @@
-- { echo }
SELECT toDateTime64('2205-12-12 12:12:12', 0, 'UTC');
SELECT toDateTime64('2205-12-12 12:12:12', 0, 'Europe/Moscow');
SELECT toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow');
SELECT toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow');