@@ -120,11 +120,10 @@ pub struct ApiBuffer<'a> {
120120#[ repr( C ) ]
121121#[ derive( Debug , Clone ) ]
122122pub struct Time {
123- /// Seconds since 2000-01-01T00:00:00Z
124- pub seconds_since_epoch : u32 ,
125- /// Number of 60 Hz frames that have elapsed since the current second
126- /// began [0..59].
127- pub frames_since_second : u8 ,
123+ /// Seconds since the epoch
124+ pub secs : u32 ,
125+ /// Nanoseconds since the last second rolled over
126+ pub nsecs : u32 ,
128127}
129128
130129// ============================================================================
@@ -290,13 +289,16 @@ impl<'a> From<&'a mut [u8]> for ApiBuffer<'a> {
290289
291290impl core:: fmt:: Display for Time {
292291 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: result:: Result < ( ) , core:: fmt:: Error > {
292+ let timestamp: chrono:: DateTime < chrono:: Utc > = self . into ( ) ;
293+ write ! ( f, "{}" , timestamp)
294+ }
295+ }
296+
297+ impl From < & Time > for chrono:: DateTime < chrono:: Utc > {
298+ fn from ( time : & Time ) -> Self {
293299 use chrono:: prelude:: * ;
294300 let our_epoch = Utc . ymd ( 2001 , 1 , 1 ) . and_hms ( 0 , 0 , 0 ) . timestamp ( ) ;
295- let time = chrono:: Utc . timestamp (
296- i64:: from ( self . seconds_since_epoch ) + our_epoch,
297- ( ( u32:: from ( self . frames_since_second ) * 1_000_000 ) / 60 ) * 1_000 ,
298- ) ;
299- write ! ( f, "{}" , time)
301+ chrono:: Utc . timestamp ( i64:: from ( time. secs ) + our_epoch, time. nsecs )
300302 }
301303}
302304
0 commit comments