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

Add try_from_* methods, rename some from_* #17

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let dt = clock.now().duration_since(t1);
println!("Elapsed: {}s, {}ns", dt.as_secs(), dt.subsec_nanos());

// Print out `t1` as a GPS timestamp.
let gps_t1: GpsTime = t1.to_tai_time();
let gps_t1: GpsTime = t1.to_tai_time().unwrap();
println!("GPS timestamp: {}s, {}ns", gps_t1.as_secs(), gps_t1.subsec_nanos());
```

Expand All @@ -98,7 +98,7 @@ use tai_time::{MonotonicTime, Tai1958Time};
// [±][Y]...[Y]YYYY-MM-DD hh:mm:ss[.d[d]...[d]]
// or:
// [±][Y]...[Y]YYYY-MM-DD'T'hh:mm:ss[.d[d]...[d]]
let t0 = MonotonicTime::from_date_time(2222, 11, 11, 12, 34, 56, 789000000).unwrap();
let t0 = MonotonicTime::try_from_date_time(2222, 11, 11, 12, 34, 56, 789000000).unwrap();
assert_eq!("2222-11-11 12:34:56.789".parse(), Ok(t0));

assert_eq!(
Expand Down
5 changes: 3 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use core::fmt;

/// The error type returned when the result of a conversion to or from a
/// [`TaiTime`](crate::TaiTime) is outside the representable range.
/// [`TaiTime`](crate::TaiTime) is outside the representable range, or the
/// conversion would cause the result to overflow.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OutOfRangeError(pub(crate) ());
Expand Down Expand Up @@ -53,7 +54,7 @@ impl fmt::Display for DateTimeError {
Self::InvalidNanosecond(nanosec) => {
write!(fmt, "nanosecond value '{}' is not valid", nanosec)
}
Self::OutOfRange => "timestamp out of representable range".fmt(fmt),
Self::OutOfRange => "timestamp outside representable range".fmt(fmt),
}
}
}
Expand Down
Loading
Loading