fix: underflow (#370)

This commit is contained in:
Nathan.fooo 2024-03-05 15:21:45 +08:00 committed by GitHub
parent 0b0a078b29
commit 9ddf32971f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -433,8 +433,13 @@ struct LastSyncTime {
impl LastSyncTime {
fn new() -> Self {
let now = Instant::now();
let one_hour = Duration::from_secs(3600);
// Use checked_sub to safely attempt subtraction, falling back to 'now' if underflow would occur
let one_hour_ago = now.checked_sub(one_hour).unwrap_or(now);
LastSyncTime {
last_sync: Mutex::new(Instant::now() - Duration::from_secs(3600)),
last_sync: Mutex::new(one_hour_ago),
}
}