Fix formatting of tendermint::Time values #775
Merged
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.
Close: #774
The
Time
datatype needs to be formatted the same way asGo's
time.RFC3339Nano
format, ie. a RFC3339 date-timewith left-padded nanoseconds digits without trailing zeros
and no trailing dot.
This is taken care of by the
to_rfc339_nanos
function inthe
tendermint_proto::serializers::timestamp
module.Prior to this commit, this function would incorrectly
trim the leading zeros of the nanoseconds digits, which
would break the
Time
-> String ->Time
roundtrip.For example, the date "2021-01-07T17:52:04.034475Z" was serialized
as "2021-01-07T17:52:04.34475Z", which then decodes to
"2021-01-07T17:52:04.344750Z", shifting the leading zero to the end.
This commit fixes
to_rfc339_nanos
function by usingchrono
'sformatting facilities to preserve the precision of the nanoseconds,
and then manually trim the trailing zeros and dot.