Skip to content

Commit 41af2da

Browse files
committed
Doc <3 for Timestamp
1 parent 9b11935 commit 41af2da

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/std/src/timestamp.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ use crate::math::Uint64;
77
/// A point in time in nanosecond precision.
88
///
99
/// This type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.
10+
///
11+
/// ## Examples
12+
///
13+
/// ```
14+
/// # use cosmwasm_std::Timestamp;
15+
/// let ts = Timestamp::from_nanos(1_000_000_202);
16+
/// assert_eq!(ts.nanos(), 1_000_000_202);
17+
/// assert_eq!(ts.seconds(), 1);
18+
/// assert_eq!(ts.subsec_nanos(), (202));
19+
///
20+
/// let ts = ts.plus_seconds(2);
21+
/// assert_eq!(ts.nanos(), 3_000_000_202);
22+
/// assert_eq!(ts.seconds(), 3);
23+
/// assert_eq!(ts.subsec_nanos(), (202));
24+
/// ```
1025
#[derive(
1126
Serialize, Deserialize, Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, JsonSchema,
1227
)]
@@ -53,7 +68,8 @@ impl Timestamp {
5368
self.0.u64() / 1_000_000_000
5469
}
5570

56-
/// Returns seconds since epoch (truncate nanoseconds)
71+
/// Returns nanoseconds since the last whole second (the remainder truncated
72+
/// by `seconds()`)
5773
#[inline]
5874
pub fn subsec_nanos(&self) -> u64 {
5975
self.0.u64() % 1_000_000_000

0 commit comments

Comments
 (0)