Backport #67583 to 24.3: Fix the upper bound of function fromModifiedJulianDay()

This commit is contained in:
robot-clickhouse 2024-08-28 08:08:08 +00:00
parent cf4b6fb66f
commit 3f26297cfe
5 changed files with 10 additions and 6 deletions

View File

@ -2968,7 +2968,7 @@ Result:
## fromModifiedJulianDay ## fromModifiedJulianDay
Converts a [Modified Julian Day](https://en.wikipedia.org/wiki/Julian_day#Variants) number to a [Proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) date in text form `YYYY-MM-DD`. This function supports day number from `-678941` to `2973119` (which represent 0000-01-01 and 9999-12-31 respectively). It raises an exception if the day number is outside of the supported range. Converts a [Modified Julian Day](https://en.wikipedia.org/wiki/Julian_day#Variants) number to a [Proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) date in text form `YYYY-MM-DD`. This function supports day number from `-678941` to `2973483` (which represent 0000-01-01 and 9999-12-31 respectively). It raises an exception if the day number is outside of the supported range.
**Syntax** **Syntax**

View File

@ -1156,7 +1156,7 @@ SELECT toModifiedJulianDayOrNull('2020-01-01');
## fromModifiedJulianDay {#frommodifiedjulianday} ## fromModifiedJulianDay {#frommodifiedjulianday}
将 [Modified Julian Day](https://en.wikipedia.org/wiki/Julian_day#Variants) 数字转换为 `YYYY-MM-DD` 文本格式的 [Proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) 日期。该函数支持从 `-678941``2973119` 的天数(分别代表 0000-01-01 和 9999-12-31。如果天数超出支持范围则会引发异常。 将 [Modified Julian Day](https://en.wikipedia.org/wiki/Julian_day#Variants) 数字转换为 `YYYY-MM-DD` 文本格式的 [Proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) 日期。该函数支持从 `-678941``2973483` 的天数(分别代表 0000-01-01 和 9999-12-31。如果天数超出支持范围则会引发异常。
**语法** **语法**

View File

@ -284,12 +284,12 @@ void OrdinalDate::init(int64_t modified_julian_day)
bool OrdinalDate::tryInit(int64_t modified_julian_day) bool OrdinalDate::tryInit(int64_t modified_julian_day)
{ {
/// This function supports day number from -678941 to 2973119 (which represent 0000-01-01 and 9999-12-31 respectively). /// This function supports day number from -678941 to 2973483 (which represent 0000-01-01 and 9999-12-31 respectively).
if (modified_julian_day < -678941) if (modified_julian_day < -678941)
return false; return false;
if (modified_julian_day > 2973119) if (modified_julian_day > 2973483)
return false; return false;
const auto a = modified_julian_day + 678575; const auto a = modified_julian_day + 678575;

View File

@ -4,6 +4,8 @@ Invocation with constant
2020-11-01 2020-11-01
\N \N
\N \N
0000-01-01
9999-12-31
or null or null
2020-11-01 2020-11-01
\N \N

View File

@ -6,8 +6,10 @@ SELECT fromModifiedJulianDay(0);
SELECT fromModifiedJulianDay(59154); SELECT fromModifiedJulianDay(59154);
SELECT fromModifiedJulianDay(NULL); SELECT fromModifiedJulianDay(NULL);
SELECT fromModifiedJulianDay(CAST(NULL, 'Nullable(Int64)')); SELECT fromModifiedJulianDay(CAST(NULL, 'Nullable(Int64)'));
SELECT fromModifiedJulianDay(-678942); -- { serverError 490 } SELECT fromModifiedJulianDay(-678942); -- { serverError CANNOT_FORMAT_DATETIME }
SELECT fromModifiedJulianDay(2973484); -- { serverError 490 } SELECT fromModifiedJulianDay(-678941);
SELECT fromModifiedJulianDay(2973483);
SELECT fromModifiedJulianDay(2973484); -- { serverError CANNOT_FORMAT_DATETIME }
SELECT 'or null'; SELECT 'or null';
SELECT fromModifiedJulianDayOrNull(59154); SELECT fromModifiedJulianDayOrNull(59154);