@@ -26,8 +26,8 @@ use std::sync::Arc;
2626
2727use crate :: transport:: Transport ;
2828use itertools:: Itertools ;
29+ use jiff:: Timestamp ;
2930use serde:: { Deserialize , Serialize } ;
30- use time:: OffsetDateTime ;
3131use tracing:: { debug, trace, warn} ;
3232
3333use crate :: jsonio:: { read_json, write_json} ;
@@ -83,7 +83,7 @@ pub struct Band {
8383#[ derive( Debug , Clone , Serialize , Deserialize ) ]
8484struct Head {
8585 /// Seconds since the Unix epoch when writing of this band began.
86- start_time : i64 ,
86+ start_time : i64 , // TODO: Maybe a timestamp with custom serializer
8787
8888 /// Semver string for the minimum Conserve version to read this band
8989 /// correctly.
@@ -99,7 +99,7 @@ struct Head {
9999#[ derive( Debug , Serialize , Deserialize ) ]
100100struct Tail {
101101 /// Seconds since the Unix epoch when the band was closed.
102- end_time : i64 ,
102+ end_time : i64 , // TODO: Maybe a timestamp with custom serializer
103103
104104 /// Number of index hunks in this band, to enable validation that none are missing.
105105 ///
@@ -113,10 +113,10 @@ pub struct Info {
113113 pub is_closed : bool ,
114114
115115 /// Time Conserve started writing this band.
116- pub start_time : OffsetDateTime ,
116+ pub start_time : Timestamp ,
117117
118118 /// Time this band was completed, if it is complete.
119- pub end_time : Option < OffsetDateTime > ,
119+ pub end_time : Option < Timestamp > ,
120120
121121 /// Number of hunks present in the index, if that is known.
122122 pub index_hunk_count : Option < u64 > ,
@@ -153,7 +153,7 @@ impl Band {
153153 Some ( "23.2.0" . to_owned ( ) )
154154 } ;
155155 let head = Head {
156- start_time : OffsetDateTime :: now_utc ( ) . unix_timestamp ( ) ,
156+ start_time : Timestamp :: now ( ) . as_second ( ) ,
157157 band_format_version,
158158 format_flags : format_flags. into ( ) ,
159159 } ;
@@ -171,7 +171,7 @@ impl Band {
171171 & self . transport ,
172172 BAND_TAIL_FILENAME ,
173173 & Tail {
174- end_time : OffsetDateTime :: now_utc ( ) . unix_timestamp ( ) ,
174+ end_time : Timestamp :: now ( ) . as_second ( ) ,
175175 index_hunk_count : Some ( index_hunk_count) ,
176176 } ,
177177 )
@@ -267,18 +267,14 @@ impl Band {
267267 pub async fn get_info ( & self ) -> Result < Info > {
268268 let tail_option: Option < Tail > = read_json ( & self . transport , BAND_TAIL_FILENAME ) . await ?;
269269 let start_time =
270- OffsetDateTime :: from_unix_timestamp ( self . head . start_time ) . map_err ( |_| {
271- Error :: InvalidMetadata {
272- details : format ! ( "Invalid band start timestamp {:?}" , self . head. start_time) ,
273- }
270+ Timestamp :: from_second ( self . head . start_time ) . map_err ( |_| Error :: InvalidMetadata {
271+ details : format ! ( "Invalid band start timestamp {:?}" , self . head. start_time) ,
274272 } ) ?;
275273 let end_time = tail_option
276274 . as_ref ( )
277275 . map ( |tail| {
278- OffsetDateTime :: from_unix_timestamp ( tail. end_time ) . map_err ( |_| {
279- Error :: InvalidMetadata {
280- details : format ! ( "Invalid band end timestamp {:?}" , tail. end_time) ,
281- }
276+ Timestamp :: from_second ( tail. end_time ) . map_err ( |_| Error :: InvalidMetadata {
277+ details : format ! ( "Invalid band end timestamp {:?}" , tail. end_time) ,
282278 } )
283279 } )
284280 . transpose ( ) ?;
@@ -312,7 +308,6 @@ impl Band {
312308mod tests {
313309 use std:: fs;
314310 use std:: str:: FromStr ;
315- use std:: time:: Duration ;
316311
317312 use serde_json:: json;
318313
@@ -355,7 +350,7 @@ mod tests {
355350 let dur = info. end_time . expect ( "info has an end_time" ) - info. start_time ;
356351 // Test should have taken (much) less than 5s between starting and finishing
357352 // the band. (It might fail if you set a breakpoint right there.)
358- assert ! ( dur < Duration :: from_secs ( 5 ) ) ;
353+ assert ! ( dur. get_seconds ( ) < 5 ) ;
359354 }
360355
361356 #[ tokio:: test]
0 commit comments