11use anyhow:: Result ;
22use db:: sqlez:: bindable:: { Bind , Column , StaticColumnCount } ;
33use db:: sqlez:: statement:: Statement ;
4+ use fs:: MTime ;
45use std:: path:: PathBuf ;
5- use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
66
77use db:: sqlez_macros:: sql;
88use db:: { define_connection, query} ;
@@ -14,7 +14,7 @@ pub(crate) struct SerializedEditor {
1414 pub ( crate ) abs_path : Option < PathBuf > ,
1515 pub ( crate ) contents : Option < String > ,
1616 pub ( crate ) language : Option < String > ,
17- pub ( crate ) mtime : Option < SystemTime > ,
17+ pub ( crate ) mtime : Option < MTime > ,
1818}
1919
2020impl StaticColumnCount for SerializedEditor {
@@ -29,16 +29,13 @@ impl Bind for SerializedEditor {
2929 let start_index = statement. bind ( & self . contents , start_index) ?;
3030 let start_index = statement. bind ( & self . language , start_index) ?;
3131
32- let mtime = self . mtime . and_then ( |mtime| {
33- mtime
34- . duration_since ( UNIX_EPOCH )
35- . ok ( )
36- . map ( |duration| ( duration. as_secs ( ) as i64 , duration. subsec_nanos ( ) as i32 ) )
37- } ) ;
38- let start_index = match mtime {
32+ let start_index = match self
33+ . mtime
34+ . and_then ( |mtime| mtime. to_seconds_and_nanos_for_persistence ( ) )
35+ {
3936 Some ( ( seconds, nanos) ) => {
40- let start_index = statement. bind ( & seconds, start_index) ?;
41- statement. bind ( & nanos, start_index) ?
37+ let start_index = statement. bind ( & ( seconds as i64 ) , start_index) ?;
38+ statement. bind ( & ( nanos as i32 ) , start_index) ?
4239 }
4340 None => {
4441 let start_index = statement. bind :: < Option < i64 > > ( & None , start_index) ?;
@@ -64,7 +61,7 @@ impl Column for SerializedEditor {
6461
6562 let mtime = mtime_seconds
6663 . zip ( mtime_nanos)
67- . map ( |( seconds, nanos) | UNIX_EPOCH + Duration :: new ( seconds as u64 , nanos as u32 ) ) ;
64+ . map ( |( seconds, nanos) | MTime :: from_seconds_and_nanos ( seconds as u64 , nanos as u32 ) ) ;
6865
6966 let editor = Self {
7067 abs_path,
@@ -280,12 +277,11 @@ mod tests {
280277 assert_eq ! ( have, serialized_editor) ;
281278
282279 // Storing and retrieving mtime
283- let now = SystemTime :: now ( ) ;
284280 let serialized_editor = SerializedEditor {
285281 abs_path : None ,
286282 contents : None ,
287283 language : None ,
288- mtime : Some ( now ) ,
284+ mtime : Some ( MTime :: from_seconds_and_nanos ( 100 , 42 ) ) ,
289285 } ;
290286
291287 DB . save_serialized_editor ( 1234 , workspace_id, serialized_editor. clone ( ) )
0 commit comments