Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time function toStartOfInterval(). #4304

Merged

Conversation

vitlibar
Copy link
Member

@vitlibar vitlibar commented Feb 7, 2019

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

#1201

This PR adds a new function toStartOfInterval(time_or_data, INTERVAL x unit [, time_zone]),
where unit is one of the interval units (year, quarter, month, week, day, hour, minute, second).

Example:

toStartOfInterval(now(), INTERVAL 1 week)

This function is a generalization of specific toStartOf<Unit>() functions, and it returns the same results, i.e.
toStartOfInterval(t, INTERVAL 1 year) returns the same as toStartOfYear(t),
toStartOfInterval(t, INTERVAL 1 month) returns the same as toStartOfMonth(t),
toStartOfInterval(t, INTERVAL 1 day) returns the same as toStartOfDay(t),
toStartOfInterval(t, INTERVAL 15 minute) returns the same as toStartOfFifteenMinutes(t),
and so on.

@vitlibar vitlibar force-pushed the add-function-to-start-of-interval branch 5 times, most recently from 2dbee06 to a850ce5 Compare February 10, 2019 16:24
@vitlibar vitlibar force-pushed the add-function-to-start-of-interval branch from a850ce5 to 0dd1dc2 Compare February 11, 2019 11:59
@vitlibar vitlibar changed the title [WIP] Add time function toStartOfInterval(). Add time function toStartOfInterval(). Feb 11, 2019
time_t date = find(t).date;
return date + (t - date) / 600 * 600;
}
inline time_t toStartOfTenMinutes(time_t t) const { return t / 600 * 600; }
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed to be more consistent with other toStartOf*Minutes() functions and to produce equal results with toStartOfInterval(t, INTERVAL 10 minute).

@alexey-milovidov alexey-milovidov merged commit 4e12697 into ClickHouse:master Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants