Skip to content

Add to_local_time function for converting timestamps with timezones to timestmaps without timezones #11358

@alamb

Description

@alamb

Is your feature request related to a problem or challenge?

The actual need is implementing date_bin that correctly bins dates on timezone correct timestamps (e.g. not UTC) as described by @Abdullahsab3 in #10368

This ticket tracks adding the to_local_time function portion of @Abdullahsab3 's suggestion in DataFusion while we work on getting consensus if we want to change the semantics of the arrow cast kernel: apache/arrow-rs#5826

Describe the solution you'd like

Add function to_local_time that takes a timestamp/column as an argument, and a timezone as another argument. For example

> select to_local_time('2020-11-30T08:00:00.000Z'::timestamp, 'Europe/Brussels');
-- translates to '2020-11-30T08:00:00.000Z'::timestamp + interval '1 hour'
< '2020-11-30T09:00:00'

The difference between this and the at time zone operator is:
The at time zone operator seems to be only adding timezone/offset information to the timestamp if I understood correctly. the proposed to_local_time function should ideally apply that offset to the provided timestamp. The same example above would be:

> select '2020-11-30T08:00:00.000Z'::timestamp at time zone 'Europe/Brussels';
+----------------------------------+
| Utf8("2020-11-30T08:00:00.000Z") |
+----------------------------------+
| 2020-11-30T08:00:00+01:00        |
+----------------------------------+
1 row in set. Query took 0.002 seconds.

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions