This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
Fixed casting of utf8 <> Timestamp with and without timezone #376
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes multiple errors in
cast
timestamps with timezones to and from utf8. It also systematizes the rules.This PR adds a new optional dependency,
chrono-tz
, that is used for calculations with timezones other than"+WX:YZ"
and"UTC"
. Those timezones have offsets that vary in time (e.g. DST), whichchrono-tz
solves. When the feature is not active and the timezone is e.g."London"
, the cast errors.Utf8 in
RFC3339
<-> Timestamp with timezoneThese casts are lossless. Strings with different timezones are mapped accordingly to the target timezone via offsets (handled by
chrono
andchrono-tz
).Utf8 without timezone -> Timestamp with timezone
These casts result in nulls (on an element-by-element basis). There is no unique way of converting these. Users need to perform two casts to add a timezone to a string without a timezone:
Utf8 -> Timestamp(_, None) -> Timestamp(_, Some(tz))
, where the latter isO(1)
and is where the user is explicit about the assumption that the time is in that timezone.Utf8 -> Timestamp without timezone
These casts are null iff the string is not in RFC3339. Other formats should be handled by
temporal_conversions::utf8_to_timestamp_ns
andtemporal_conversions::utf8_to_naive_timestamp_ns
, whose one of the arguments is the format (e.g."%Y-%m-%dT%H:%M:%S%.f%:z"
forRFC3339
).Timestamp without timezone -> Utf8
It is printed in the
ISO 8601
format without timezone information (e.g.1996-12-19 16:39:57
), which is the display offered bychrono::NaiveDateTime
.Displaying timestamps follows the same rules as
timestamp -> utf8
Overall, this offers a more controlled environment over timezones.