Skip to content

Commit c193681

Browse files
committed
Merge #56: Fix timestamp code duplications
9c65526 Refactor: deduplicate timestamp logic & remove excessive clippy allows (Oleksandr Zahorodnyi) Pull request description: This PR deduplicates the logic for retrieving the current Unix timestamp and remove excessive clippy allows in `interactive.rs` ACKs for top commit: KyrylR: ACK 9c65526 Tree-SHA512: b7a43a4bc72839529f79b1e3e5530dba4df1f22998cd5535a6ad2fb81dd883591ba77752e5b147117ca019bf09d6cd9bbd23384caa15335f1e6af66cab669642
2 parents 04adcd2 + 9c65526 commit c193681

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

crates/cli-client/src/cli/interactive.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ pub struct TokenDisplay {
2626

2727
/// Format a past timestamp as "X ago" for history entries.
2828
#[must_use]
29-
#[allow(clippy::cast_possible_wrap)]
3029
pub fn format_time_ago(timestamp: i64) -> String {
31-
let now = SystemTime::now()
32-
.duration_since(UNIX_EPOCH)
33-
.map(|d| d.as_secs() as i64)
34-
.unwrap_or(0);
30+
let now = current_timestamp();
3531

3632
let diff_secs = now - timestamp;
3733

@@ -63,12 +59,8 @@ pub fn format_time_ago(timestamp: i64) -> String {
6359

6460
/// Format a future expiry timestamp as "in X days" or "[EXPIRED]".
6561
#[must_use]
66-
#[allow(clippy::cast_possible_wrap)]
6762
pub fn format_relative_time(expiry_timestamp: i64) -> String {
68-
let now = SystemTime::now()
69-
.duration_since(UNIX_EPOCH)
70-
.map(|d| d.as_secs() as i64)
71-
.unwrap_or(0);
63+
let now = current_timestamp();
7264

7365
let diff_secs = expiry_timestamp - now;
7466

@@ -556,7 +548,7 @@ mod tests {
556548
#[test]
557549
#[allow(clippy::cast_possible_wrap)]
558550
fn test_format_relative_time() {
559-
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() as i64;
551+
let now = current_timestamp();
560552

561553
assert_eq!(format_relative_time(now - 100), "[EXPIRED]");
562554

0 commit comments

Comments
 (0)