Skip to content

Commit 7af49ff

Browse files
committed
nostr: add Timestamp::from_i64_secs
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 4ff35fe commit 7af49ff

File tree

1 file changed

+10
-0
lines changed
  • crates/nostr/src/types/time

1 file changed

+10
-0
lines changed

crates/nostr/src/types/time/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ impl Timestamp {
4242
Self(secs)
4343
}
4444

45+
/// Construct from seconds
46+
#[inline]
47+
pub const fn from_i64_secs(secs: i64) -> Self {
48+
if secs <= 0 {
49+
Self::zero()
50+
} else {
51+
Self::from_secs(secs as u64)
52+
}
53+
}
54+
4555
/// Compose `0` timestamp
4656
#[inline]
4757
pub const fn zero() -> Self {

0 commit comments

Comments
 (0)