Skip to content

Commit

Permalink
Guidance around using google.type.Interval for timestamp ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
jskeet committed Feb 9, 2022
1 parent fab6a91 commit 7fedf83
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions aip/general/0145.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ Exclusive end values are preferable for the following reasons:
- It is easier to reason about abutting ranges: `[0, x), [x, y), [y, z)`, where
values are chainable from one range to the next.

### Timestamp intervals

The following section describes the use of the [google.type.Interval][interval]
type, found amongst the common protos that are described in [AIP-213][].
This type represents a range between two timestamps, with an inclusive start
value and exclusive end value.

Ranges between two timestamps which conform to the expectations of the
`Interval` message **should** use this rather than having separate start and
end fields. This allows client code to be written against the `Interval`
message (such as checking whether a given timestamp occurs within the interval)
and reused across multiple intervals in the same API, or even across multiple
APIs.

APIs **may** use start and end timestamp fields instead. In particular, if a
message within an API is inherently describing an interval with extra
information about that interval, the additional level of nesting introduced
by using the `Interval` message may be undesirable.

### Exceptions

In some cases, there is significant colloquial precedent for inclusive start
Expand Down Expand Up @@ -80,3 +99,6 @@ start and end values **should** use inclusive end values with `first_` and
`last_` prefixes for those ranges only. The service **should** still use
exclusive end values for other ranges where this does not apply, and **must**
clearly document each range as inclusive or exclusive.

[aip-213]: ./0213.md
[interval]: https://github.com/googleapis/googleapis/blob/master/google/type/interval.proto

0 comments on commit 7fedf83

Please sign in to comment.