pub struct PublishTime(/* private fields */);Expand description
A release publish instant, normalized to Unix epoch seconds (UTC).
Copy and cheap to pass around, so it fits into Box<dyn Version>
trait objects without lifetime or allocation concerns.
§Examples
use deps_core::PublishTime;
let published = PublishTime::parse_rfc3339("2026-07-18T23:05:13Z").unwrap();
let now = PublishTime::from_unix_secs(published.as_unix_secs() + 3600);
assert_eq!(published.age_secs_from(now), 3600);Implementations§
Source§impl PublishTime
impl PublishTime
Sourcepub fn now() -> Self
pub fn now() -> Self
Returns the current time as a PublishTime.
Uses std::time::SystemTime rather than the time crate’s own
“now” APIs, so this module never needs the local-offset/
wasm-bindgen features. A clock before the Unix epoch saturates to 0.
§Examples
use deps_core::PublishTime;
let now = PublishTime::now();
assert!(now.as_unix_secs() > 0);Sourcepub const fn from_unix_secs(secs: i64) -> Self
pub const fn from_unix_secs(secs: i64) -> Self
Builds a PublishTime directly from Unix epoch seconds.
§Examples
use deps_core::PublishTime;
let t = PublishTime::from_unix_secs(1_753_052_713);
assert_eq!(t.as_unix_secs(), 1_753_052_713);Sourcepub fn parse_rfc3339(s: &str) -> Option<Self>
pub fn parse_rfc3339(s: &str) -> Option<Self>
Parses an RFC 3339 timestamp string into a PublishTime.
Accepts every shape seen across v1 registries: a bare Z suffix,
arbitrary fractional-second digits, and a numeric UTC offset
(+00:00). Returns None on any parse failure — per US-003, a
missing or malformed timestamp degrades to pre-feature behavior
rather than surfacing an error.
§Examples
use deps_core::PublishTime;
assert!(PublishTime::parse_rfc3339("2026-07-18T23:05:13Z").is_some());
assert!(PublishTime::parse_rfc3339("2026-05-14T19:25:27.735762Z").is_some());
assert!(PublishTime::parse_rfc3339("2026-01-02T08:56:05+00:00").is_some());
assert!(PublishTime::parse_rfc3339("not a timestamp").is_none());
assert!(PublishTime::parse_rfc3339("").is_none());Sourcepub const fn as_unix_secs(self) -> i64
pub const fn as_unix_secs(self) -> i64
Returns this instant as Unix epoch seconds.
§Examples
use deps_core::PublishTime;
let t = PublishTime::from_unix_secs(42);
assert_eq!(t.as_unix_secs(), 42);Sourcepub const fn age_secs_from(self, now: Self) -> u64
pub const fn age_secs_from(self, now: Self) -> u64
Age of this publish instant relative to now, in seconds.
A self in the future relative to now (clock skew, or a registry
timestamp bug) saturates to age 0 rather than underflowing or
returning a negative duration — chosen because a slightly-ahead
registry clock is exactly the “just published” case the freshness
signal exists to surface, so clamping preserves the signal instead of
silently losing it.
§Examples
use deps_core::PublishTime;
let published = PublishTime::from_unix_secs(1_000);
let now = PublishTime::from_unix_secs(1_100);
assert_eq!(published.age_secs_from(now), 100);
// Clock skew: published "after" now clamps to 0, not a negative age.
let future = PublishTime::from_unix_secs(2_000);
assert_eq!(future.age_secs_from(now), 0);Trait Implementations§
Source§impl Clone for PublishTime
impl Clone for PublishTime
Source§fn clone(&self) -> PublishTime
fn clone(&self) -> PublishTime
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for PublishTime
Source§impl Debug for PublishTime
impl Debug for PublishTime
impl Eq for PublishTime
Source§impl Ord for PublishTime
impl Ord for PublishTime
Source§fn cmp(&self, other: &PublishTime) -> Ordering
fn cmp(&self, other: &PublishTime) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for PublishTime
impl PartialEq for PublishTime
Source§fn eq(&self, other: &PublishTime) -> bool
fn eq(&self, other: &PublishTime) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for PublishTime
impl PartialOrd for PublishTime
impl StructuralPartialEq for PublishTime
Auto Trait Implementations§
impl Freeze for PublishTime
impl RefUnwindSafe for PublishTime
impl Send for PublishTime
impl Sync for PublishTime
impl Unpin for PublishTime
impl UnsafeUnpin for PublishTime
impl UnwindSafe for PublishTime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.