File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
lightning-liquidity/src/lsps0 Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ use crate::lsps2::msgs::{
1818} ;
1919use crate :: prelude:: { HashMap , String } ;
2020
21+ use chrono:: DateTime ;
2122use lightning:: ln:: msgs:: { DecodeError , LightningError } ;
2223use lightning:: ln:: wire;
2324use lightning:: util:: ser:: { LengthLimitedRead , LengthReadable , WithoutLength } ;
@@ -27,6 +28,7 @@ use bitcoin::secp256k1::PublicKey;
2728use core:: fmt:: { self , Display } ;
2829use core:: str:: FromStr ;
2930
31+ use core:: time:: Duration ;
3032#[ cfg( feature = "std" ) ]
3133use std:: time:: { SystemTime , UNIX_EPOCH } ;
3234
@@ -212,6 +214,17 @@ impl LSPSDateTime {
212214 self . 0 . timestamp ( ) . try_into ( ) . expect ( "expiration to be ahead of unix epoch" ) ;
213215 now_seconds_since_epoch > datetime_seconds_since_epoch
214216 }
217+
218+ /// Returns the time in seconds since the unix epoch.
219+ pub fn abs_diff ( & self , other : & Self ) -> u64 {
220+ self . 0 . timestamp ( ) . abs_diff ( other. 0 . timestamp ( ) )
221+ }
222+ }
223+
224+ impl From < Duration > for LSPSDateTime {
225+ fn from ( duration : Duration ) -> Self {
226+ Self ( DateTime :: UNIX_EPOCH + duration)
227+ }
215228}
216229
217230impl FromStr for LSPSDateTime {
You can’t perform that action at this time.
0 commit comments