Skip to content

function toStartOfSecond(DateTime64) -> DateTime64#10722

Merged
alexey-milovidov merged 1 commit intoClickHouse:masterfrom
Enmk:DateTime64_fixes
May 11, 2020
Merged

function toStartOfSecond(DateTime64) -> DateTime64#10722
alexey-milovidov merged 1 commit intoClickHouse:masterfrom
Enmk:DateTime64_fixes

Conversation

@Enmk
Copy link
Contributor

@Enmk Enmk commented May 7, 2020

This function nullifies the sub-second part of DateTime64 value.

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
New function function toStartOfSecond(DateTime64) -> DateTime64 that nullifies sub-second part of DateTime64 value.

Detailed description / Documentation draft:

toStartOfSecond(value, timezone)

Returns new DateTime64 with nullified sub-second part and (optionally) different timezone.

  • value - DateTime64
  • timezone - String, optional timezone for the return value.
  • return - a DateTime64 of the same precision (and same timezone unless specified explicitly) as value, but with sub-second part nullified.

Example:

WITH toDateTime64('2019-09-16 19:20:11.123', 3) AS dt64 SELECT toStartOfSecond(dt64);
┌───toStartOfSecond(dt64)─┐
│ 2019-09-16 19:20:11.000 │
└─────────────────────────┘

...

@blinkov blinkov added doc-alert pr-feature Pull request with new product feature labels May 7, 2020
@Enmk Enmk changed the title WIP: New function toStartOfSecond(DateTime64) -> DateTime64 New function toStartOfSecond(DateTime64) -> DateTime64 May 8, 2020
@Enmk Enmk changed the title New function toStartOfSecond(DateTime64) -> DateTime64 function toStartOfSecond(DateTime64) -> DateTime64 May 8, 2020
@alexey-milovidov alexey-milovidov self-assigned this May 8, 2020
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe result = -result will look better?
(no difference in the behaviour indeed)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look correct for negative values (that will be introduced in another PR).

Example:

value is -0.3
fractional part that you calculate is 0.3
value - fractional = -0.6

But if I understand correctly, you want to round down to -1.0 (towards minus infinity).

Copy link
Contributor Author

@Enmk Enmk May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks old-fashioned, maybe it's possible to use std::enable_if_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small questions remain.

This funtion nullifies sub-second part of DateTime64 value.
@alexey-milovidov alexey-milovidov merged commit 1e70230 into ClickHouse:master May 11, 2020
@Enmk Enmk deleted the DateTime64_fixes branch December 8, 2020 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants