mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #51290 from arenadata/Fix-formatDateTime-with-fractional-negative-datetime64
Fix formatDateTime() with fractional negative datetime64
This commit is contained in:
commit
12432ac582
@ -943,7 +943,16 @@ public:
|
||||
{
|
||||
if constexpr (std::is_same_v<DataType, DataTypeDateTime64>)
|
||||
{
|
||||
const auto c = DecimalUtils::split(vec[i], scale);
|
||||
auto c = DecimalUtils::split(vec[i], scale);
|
||||
|
||||
// -1.123 splits to -1 / 0.123
|
||||
if (vec[i].value < 0 && c.fractional)
|
||||
{
|
||||
using F = typename DataType::FieldType;
|
||||
c.fractional = DecimalUtils::scaleMultiplier<F>(scale) + (c.whole ? F(-1) : F(1)) * c.fractional;
|
||||
--c.whole;
|
||||
}
|
||||
|
||||
for (auto & instruction : instructions)
|
||||
instruction.perform(pos, static_cast<Int64>(c.whole), c.fractional, scale, time_zone);
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
1900-01-01 00:00:00.000
|
||||
1962-12-08 18:11:29.123
|
||||
1969-12-31 23:59:59.999
|
||||
1970-01-01 00:00:00.000
|
||||
1970-01-01 00:00:00.001
|
5
tests/queries/0_stateless/00718_format_datetime_1.sql
Normal file
5
tests/queries/0_stateless/00718_format_datetime_1.sql
Normal file
@ -0,0 +1,5 @@
|
||||
select formatDateTime(toDateTime64('1900-01-01 00:00:00.000', 3, 'UTC'), '%F %T.%f');
|
||||
select formatDateTime(toDateTime64('1962-12-08 18:11:29.123', 3, 'UTC'), '%F %T.%f');
|
||||
select formatDateTime(toDateTime64('1969-12-31 23:59:59.999', 3, 'UTC'), '%F %T.%f');
|
||||
select formatDateTime(toDateTime64('1970-01-01 00:00:00.000', 3, 'UTC'), '%F %T.%f');
|
||||
select formatDateTime(toDateTime64('1970-01-01 00:00:00.001', 3, 'UTC'), '%F %T.%f');
|
Loading…
Reference in New Issue
Block a user