Skip to content

Avoid wraparound (timestamp underflow) in toStartOfWeek() #26137

@markheger

Description

@markheger

toStartofWeek() does a wraparound (timestamp underflow) in case the timestamp 0 or 1970-01-01 00:00:00

1970-01-01 00:00:00 causes the wraparound since the first day of 1970 is a Thursday.

The result 2106-02-07 does not really make sense.

WITH toDateTime('1970-01-01 00:00:00', 'UTC') AS ts
SELECT toStartOfWeek(ts)

┌─toStartOfWeek(ts)─┐
│        2106-02-07 │
└───────────────────┘
WITH toDateTime(0, 'UTC') AS ts
SELECT toStartOfWeek(ts)

┌─toStartOfWeek(ts)─┐
│        2106-02-07 │
└───────────────────┘

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-datetimeDate/DateTime/TimeZone datatypes and date-time semantics.feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions