@@ -6,7 +6,7 @@ use std::ops::Deref;
66use std:: path:: { Path , PathBuf } ;
77use std:: sync:: atomic:: { AtomicBool , Ordering } ;
88use std:: sync:: Arc ;
9- use std:: time:: { Duration , Instant , SystemTime } ;
9+ use std:: time:: Duration ;
1010
1111use anyhow:: { bail, ensure, Context as _, Result } ;
1212use async_channel:: { self as channel, Receiver , Sender } ;
@@ -33,7 +33,7 @@ use crate::scheduler::{convert_folder_meaning, SchedulerState};
3333use crate :: sql:: Sql ;
3434use crate :: stock_str:: StockStrings ;
3535use crate :: timesmearing:: SmearedTimestamp ;
36- use crate :: tools:: { create_id, duration_to_str, time} ;
36+ use crate :: tools:: { self , create_id, duration_to_str, time, time_elapsed } ;
3737
3838/// Builder for the [`Context`].
3939///
@@ -233,15 +233,15 @@ pub struct InnerContext {
233233 /// IMAP METADATA.
234234 pub ( crate ) metadata : RwLock < Option < ServerMetadata > > ,
235235
236- pub ( crate ) last_full_folder_scan : Mutex < Option < Instant > > ,
236+ pub ( crate ) last_full_folder_scan : Mutex < Option < tools :: Time > > ,
237237
238238 /// ID for this `Context` in the current process.
239239 ///
240240 /// This allows for multiple `Context`s open in a single process where each context can
241241 /// be identified by this ID.
242242 pub ( crate ) id : u32 ,
243243
244- creation_time : SystemTime ,
244+ creation_time : tools :: Time ,
245245
246246 /// The text of the last error logged and emitted as an event.
247247 /// If the ui wants to display an error after a failure,
@@ -262,7 +262,7 @@ enum RunningState {
262262 Running { cancel_sender : Sender < ( ) > } ,
263263
264264 /// Cancel signal has been sent, waiting for ongoing process to be freed.
265- ShallStop { request : Instant } ,
265+ ShallStop { request : tools :: Time } ,
266266
267267 /// There is no ongoing process, a new one can be allocated.
268268 Stopped ,
@@ -394,7 +394,7 @@ impl Context {
394394 new_msgs_notify,
395395 server_id : RwLock :: new ( None ) ,
396396 metadata : RwLock :: new ( None ) ,
397- creation_time : std :: time :: SystemTime :: now ( ) ,
397+ creation_time : tools :: Time :: now ( ) ,
398398 last_full_folder_scan : Mutex :: new ( None ) ,
399399 last_error : std:: sync:: RwLock :: new ( "" . to_string ( ) ) ,
400400 debug_logging : std:: sync:: RwLock :: new ( None ) ,
@@ -454,7 +454,7 @@ impl Context {
454454 }
455455
456456 let address = self . get_primary_self_addr ( ) . await ?;
457- let time_start = std :: time :: SystemTime :: now ( ) ;
457+ let time_start = tools :: Time :: now ( ) ;
458458 info ! ( self , "background_fetch started fetching {address}" ) ;
459459
460460 let _pause_guard = self . scheduler . pause ( self . clone ( ) ) . await ?;
@@ -476,7 +476,10 @@ impl Context {
476476 let quota = self . quota . read ( ) . await ;
477477 quota
478478 . as_ref ( )
479- . filter ( |quota| quota. modified + DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT > time ( ) )
479+ . filter ( |quota| {
480+ time_elapsed ( & quota. modified )
481+ > Duration :: from_secs ( DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT )
482+ } )
480483 . is_none ( )
481484 } ;
482485
@@ -489,7 +492,7 @@ impl Context {
489492 info ! (
490493 self ,
491494 "background_fetch done for {address} took {:?}" ,
492- time_start . elapsed ( ) . unwrap_or_default ( )
495+ time_elapsed ( & time_start ) ,
493496 ) ;
494497
495498 Ok ( ( ) )
@@ -591,7 +594,7 @@ impl Context {
591594 pub ( crate ) async fn free_ongoing ( & self ) {
592595 let mut s = self . running_state . write ( ) . await ;
593596 if let RunningState :: ShallStop { request } = * s {
594- info ! ( self , "Ongoing stopped in {:?}" , request . elapsed ( ) ) ;
597+ info ! ( self , "Ongoing stopped in {:?}" , time_elapsed ( & request ) ) ;
595598 }
596599 * s = RunningState :: Stopped ;
597600 }
@@ -606,7 +609,7 @@ impl Context {
606609 }
607610 info ! ( self , "Signaling the ongoing process to stop ASAP." , ) ;
608611 * s = RunningState :: ShallStop {
609- request : Instant :: now ( ) ,
612+ request : tools :: Time :: now ( ) ,
610613 } ;
611614 }
612615 RunningState :: ShallStop { .. } | RunningState :: Stopped => {
@@ -867,8 +870,8 @@ impl Context {
867870 . to_string ( ) ,
868871 ) ;
869872
870- let elapsed = self . creation_time . elapsed ( ) ;
871- res. insert ( "uptime" , duration_to_str ( elapsed. unwrap_or_default ( ) ) ) ;
873+ let elapsed = time_elapsed ( & self . creation_time ) ;
874+ res. insert ( "uptime" , duration_to_str ( elapsed) ) ;
872875
873876 Ok ( res)
874877 }
@@ -1214,7 +1217,7 @@ pub fn get_version_str() -> &'static str {
12141217
12151218#[ cfg( test) ]
12161219mod tests {
1217- use std:: time:: Duration ;
1220+ use std:: time:: { Duration , SystemTime } ;
12181221
12191222 use anyhow:: Context as _;
12201223 use strum:: IntoEnumIterator ;
0 commit comments