Add toStableRelativeHourNum

This commit is contained in:
Roman Vasin 2022-10-18 09:07:12 +00:00
parent 5a36b99933
commit d9fcd91875
2 changed files with 17 additions and 4 deletions

View File

@ -895,6 +895,19 @@ public:
return toRelativeHourNum(lut[toLUTIndex(v)].date);
}
/// The same formula is used for positive time (after Unix epoch) and negative time (before Unix epoch).
/// Its needed for correct work of dateDiff function.
inline Time toStableRelativeHourNum(Time t) const
{
return (t + DATE_LUT_ADD + 86400 - offset_at_start_of_epoch) / 3600 - (DATE_LUT_ADD / 3600);
}
template <typename DateOrTime>
inline Time toStableRelativeHourNum(DateOrTime v) const
{
return toStableRelativeHourNum(lut[toLUTIndex(v)].date);
}
inline Time toRelativeMinuteNum(Time t) const /// NOLINT
{
return (t + DATE_LUT_ADD) / 60 - (DATE_LUT_ADD / 60);

View File

@ -159,19 +159,19 @@ struct ToExtendedRelativeHourNumImpl
static inline Int64 execute(Int64 t, const DateLUTImpl & time_zone)
{
return time_zone.toRelativeHourNum(t);
return time_zone.toStableRelativeHourNum(t);
}
static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
{
return time_zone.toRelativeHourNum(static_cast<time_t>(t));
return time_zone.toStableRelativeHourNum(static_cast<time_t>(t));
}
static inline Int64 execute(Int32 d, const DateLUTImpl & time_zone)
{
return time_zone.toRelativeHourNum(ExtendedDayNum(d));
return time_zone.toStableRelativeHourNum(ExtendedDayNum(d));
}
static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
{
return time_zone.toRelativeHourNum(DayNum(d));
return time_zone.toStableRelativeHourNum(DayNum(d));
}
using FactorTransform = ZeroTransform;