@@ -1213,6 +1213,12 @@ impl Invoice {
1213
1213
self . signed_invoice . recover_payee_pub_key ( ) . expect ( "was checked by constructor" ) . 0
1214
1214
}
1215
1215
1216
+ /// Returns the Duration since the Unix epoch at which the invoice expires.
1217
+ /// Returning None if overflow occurred.
1218
+ pub fn expires_at ( & self ) -> Option < Duration > {
1219
+ self . duration_since_epoch ( ) . checked_add ( self . expiry_time ( ) )
1220
+ }
1221
+
1216
1222
/// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1217
1223
pub fn expiry_time ( & self ) -> Duration {
1218
1224
self . signed_invoice . expiry_time ( )
@@ -1235,6 +1241,20 @@ impl Invoice {
1235
1241
}
1236
1242
}
1237
1243
1244
+ /// Returns the Duration remaining until the invoice expires.
1245
+ #[ cfg( feature = "std" ) ]
1246
+ pub fn duration_until_expiry ( & self ) -> Duration {
1247
+ SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH )
1248
+ . map ( |now| self . expiration_remaining_from_epoch ( now) )
1249
+ . unwrap_or ( Duration :: ZERO )
1250
+ }
1251
+
1252
+ /// Returns the Duration remaining until the invoice expires given the current time.
1253
+ /// `time` is the timestamp as a duration since the Unix epoch.
1254
+ pub fn expiration_remaining_from_epoch ( & self , time : Duration ) -> Duration {
1255
+ self . expires_at ( ) . map ( |x| x. checked_sub ( time) ) . flatten ( ) . unwrap_or ( Duration :: ZERO )
1256
+ }
1257
+
1238
1258
/// Returns whether the expiry time would pass at the given point in time.
1239
1259
/// `at_time` is the timestamp as a duration since the Unix epoch.
1240
1260
pub fn would_expire ( & self , at_time : Duration ) -> bool {
0 commit comments