apache / apache/arrow

[C++] interval_between(timestamptz, timestamptz) -> struct kernel

Open
#18,858 17 comments 0 reactions 1 assignee Claimed by @rok View on GitHub
Component: C++ Type: task
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

Given two timestamps that each have time zones this function should return an interval from the first timestamp to the second timestamp according to the following rules (postgres rules):

- 1 day is 24 physical hours (which may not exactly equal 1 calendar day).
- Intervals returned will never contain a months/years field

Examples:

interval_between('2021-03-14 00:00:00 America/Denver', '2021-03-15 00:00:00 America/Denver') => { "hours": 23 }
interval_between('2021-03-14 00:00:00 UTC', '2021-03-15 00:00:00 UTC') => { "days": 1}
interval_between('2021-03-14 00:00:00 UTC', '2020-03-14 00:00:00 UTC') => { "days": 365}

If the first timestamp is larger than the second timestamp then the interval will be negative.

**Reporter**: [Weston Pace](https://issues.apache.org/jira/browse/ARROW-14108) / @westonpace
**Assignee**: [Rok Mihevc](https://issues.apache.org/jira/browse/ARROW-14108) / @rok
**Watchers**: [Rok Mihevc](https://issues.apache.org/jira/browse/ARROW-14108) / @rok
#### PRs and other links:
- [GitHub Pull Request #12477](https://github.com/apache/arrow/pull/12477)

**Note**: *This issue was originally created as [ARROW-14108](https://issues.apache.org/jira/browse/ARROW-14108). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.