Fixed , updated docs

This commit is contained in:
zvonand 2022-08-22 17:36:10 +03:00
parent 963d838647
commit d789dabc9d
3 changed files with 18 additions and 11 deletions

View File

@ -272,7 +272,8 @@ Though these functions can take `Date32` and `DateTime64` values as an argument,
In case argument is out of normal range:
* `1970-01-01 (00:00:00)` will be returned for values prior to 1970,
* `2106-02-07 08:28:15` will be taken as argument when actual argument is above this timestamp and return type is `DateTime`,
* `2149-06-06` will be taken as argument when actual argument is above this timestamp and return type is `Date`.
* `2149-06-06` will be taken as argument when actual argument is above this timestamp and return type is `Date`,
* `2149-05-31` will be the result of execution of `toLastDayOfMonth` when argument is greater then `2149-05-31`.
:::
## toStartOfYear

View File

@ -271,12 +271,13 @@ SELECT toUnixTimestamp('2017-11-05 08:07:47', 'Asia/Tokyo') AS unix_timestamp;
:::
:::Attention
Тип возвращаемого описанными далее функциями `toStartOf*`, `toLastDayOfMonth`, `toMonday` значения - `Date` или `DateTime`.
Тип возвращаемого описанными далее функциями `toStartOf*`, `toMonday` значения - `Date` или `DateTime`.
Хотя эти функции могут принимать значения типа `Date32` или `DateTime64` в качестве аргумента, при обработке аргумента вне нормального диапазона значений (`1970` - `2148` для `Date` и `1970-01-01 00:00:00`-`2106-02-07 08:28:15` для `DateTime`) будет получен некорректный результат.
Возвращаемые значения для значений вне нормального диапазона:
* `1970-01-01 (00:00:00)` будет возвращён для моментов времени до 1970 года,
* `2106-02-07 08:28:15` будет взят в качестве аргумента, если полученный аргумент превосходит данное значение и возвращаемый тип - `DateTime`,
* `2149-06-06` будет взят в качестве аргумента, если полученный аргумент превосходит данное значение и возвращаемый тип - `Date`.
* `2149-06-06` будет взят в качестве аргумента, если полученный аргумент превосходит данное значение и возвращаемый тип - `Date`,
* `2149-05-31` будет результатом функции `toLastDayOfMonth` при обработке аргумента больше `2149-05-31`.
:::
*
## toStartOfYear {#tostartofyear}

View File

@ -114,11 +114,7 @@ struct ToStartOfDayImpl
if (t.whole < 0 || (t.whole >= 0 && t.fractional < 0))
return 0;
Int64 date_time = time_zone.fromDayNum(ExtendedDayNum(t.whole));
if (date_time <= 0xffffffff)
return date_time;
else
return time_zone.toDate(0xffffffff);
return time_zone.toDate(std::min(t.whole, time_t(0xffffffff)));
}
static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
{
@ -199,7 +195,11 @@ struct ToLastDayOfMonthImpl
static inline UInt16 execute(Int64 t, const DateLUTImpl & time_zone)
{
return t < 0 ? 0 : time_zone.toLastDayNumOfMonth(ExtendedDayNum(std::min(time_t(time_zone.toDayNum(t)), time_t(DATE_LUT_MAX_DAY_NUM))));
if (t < 0)
return 0;
/// 0xFFF9 is Int value for 2149-05-31 -- the last day where we can actually find LastDayOfMonth. This will also be the return value.
return time_zone.toLastDayNumOfMonth(ExtendedDayNum(std::min(time_t(time_zone.toDayNum(t)), time_t(0xFFF9))));
}
static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
{
@ -207,11 +207,16 @@ struct ToLastDayOfMonthImpl
}
static inline UInt16 execute(Int32 d, const DateLUTImpl & time_zone)
{
return d < 0 ? 0 : time_zone.toLastDayNumOfMonth(ExtendedDayNum(std::min(d, DATE_LUT_MAX_DAY_NUM)));
if (d < 0)
return 0;
/// 0xFFF9 is Int value for 2149-05-31 -- the last day where we can actually find LastDayOfMonth. This will also be the return value.
return time_zone.toLastDayNumOfMonth(ExtendedDayNum(std::min(d, 0xFFF9)));
}
static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
{
return time_zone.toLastDayNumOfMonth(DayNum(d));
/// 0xFFF9 is Int value for 2149-05-31 -- the last day where we can actually find LastDayOfMonth. This will also be the return value.
return time_zone.toLastDayNumOfMonth(DayNum(std::min(d, UInt16(0xFFF9))));
}
using FactorTransform = ZeroTransform;