Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change conversion of NTP64 and Timestamp to/from String #16

Merged
merged 8 commits into from
Jul 3, 2024

Conversation

JEnoch
Copy link
Member

@JEnoch JEnoch commented Jul 1, 2024

As discussed in #15 in 0.7.0 and previous versions the formatting and conversion of NTP64 and Timestamp into a String uses the RFC3339 representation, suffering of rounding and thus loss of precision when converting the fraction of seconds part into nanoseconds.
The consequence was that conversion from/to String was not bijective (i.e. you might not get back the original value after a 2-ways conversion).

This PR changes the default conversion of NTP64 and Timestamp into a String, formatting the time as an unsigned integer in decimal format. This conversion is lossless and bijective.

For conversion to RFC3339 format, those methods are added:

  • NTP64::to_string_rfc3339_lossy()
  • NTP64::parse_rfc3339()
  • formatting with the alternate flag (e.g.: println!("{:#}", my_ntp64); )
  • Timestamp::to_string_rfc3339_lossy()
  • Timestamp::parse_rfc3339()
  • formatting with the alternate flag (e.g.: println!("{:#}", my_timestamp); )

Note that those new methods are not available in no_std context.

Closes #15

@JEnoch JEnoch requested a review from Mallets July 1, 2024 16:12
@JEnoch JEnoch self-assigned this Jul 1, 2024
src/ntp64.rs Outdated Show resolved Hide resolved
src/ntp64.rs Outdated Show resolved Hide resolved
src/ntp64.rs Show resolved Hide resolved
src/ntp64.rs Show resolved Hide resolved
src/timestamp.rs Outdated Show resolved Hide resolved
@JEnoch JEnoch requested a review from Mallets July 3, 2024 14:19
@Mallets Mallets merged commit 71dba2c into master Jul 3, 2024
4 checks passed
@Mallets Mallets deleted the bijective_to_string branch July 3, 2024 15:00
@JEnoch JEnoch changed the title Change conversion of NTP64 and Timesamp to/from String Change conversion of NTP64 and Timestamp to/from String Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timestamp is not round-trip equivalent with Display and parse()
2 participants