Merge pull request #10513 from ClickHouse/fix-fractional-timezones-overflow

Fix overflow at beginning of unix epoch for fractional timezones
This commit is contained in:
alexey-milovidov 2020-04-26 21:33:53 +03:00 committed by GitHub
commit 11bb3e3afa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -287,8 +287,8 @@ public:
if (offset_is_whole_number_of_hours_everytime)
return (t / 60) % 60;
time_t date = find(t).date;
return (t - date) / 60 % 60;
UInt32 date = find(t).date;
return (UInt32(t) - date) / 60 % 60;
}
inline time_t toStartOfMinute(time_t t) const { return t / 60 * 60; }
@ -301,9 +301,8 @@ public:
if (offset_is_whole_number_of_hours_everytime)
return t / 3600 * 3600;
time_t date = find(t).date;
/// Still can return wrong values for time at 1970-01-01 if the UTC offset was non-whole number of hours.
return date + (t - date) / 3600 * 3600;
UInt32 date = find(t).date;
return date + (UInt32(t) - date) / 3600 * 3600;
}
/** Number of calendar day since the beginning of UNIX epoch (1970-01-01 is zero)

View File

@ -0,0 +1,3 @@
1970-01-01 08:16:40
16
1970-01-01 08:00:00

View File

@ -0,0 +1,3 @@
SELECT toDateTime(10000, 'Asia/Calcutta');
SELECT toMinute(toDateTime(10000, 'Asia/Calcutta'));
SELECT toStartOfHour(toDateTime(10000, 'Asia/Calcutta'));