Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impl Timestamp::{Display, FromStr} with RFC-3339 format
This PR implements to and from string methods for `prost_types::Timestamp` following the RFC-3339 timestamp format, as also specified by the [Protobuf JSON mapping spec][1]. The `Display` impl always emits the Zulu (Z) timezone, whereas the parser is slightly lenient in accepting fixed timezone offsets, as well as both the `T` and space seperated date and time portions. This leniency in parsing makes it much much more robust to parsing data of less-than-pristine formatting, even though the protobuf spec allows no leniency. Also, since it was easy with the new date time functionality, we've gone ahead and added a trio of convenience construct functions to `Timestamp` which makes it straightforward to create `Timestamp`s out of calendar date time information. This functionality will be used in follow-up PRs to add Serde [de]serialization support to the types in `prost_types`, which is itself a stepping stone towards full JSON support. This PR was extracted from tokio-rs#558, and is based on code which myself and @konradjniemiec have written, and which has been running in production at @sisudata for a few years. The to-string portion of this code has also been incorporated into [`tracing`][2], so it should be pretty well battle hardened. [1]: https://developers.google.com/protocol-buffers/docs/proto3#json [2]: https://github.com/tokio-rs/tracing/blob/master/tracing-subscriber/src/fmt/time/datetime.rs
- Loading branch information