Skip to content

Commit 27e5350

Browse files
Change abs_diff to duration_since, so it returns a duration
1 parent ec6a9f0 commit 27e5350

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lightning-liquidity/src/lsps0/ser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,10 @@ impl LSPSDateTime {
240240
now_seconds_since_epoch > datetime_seconds_since_epoch
241241
}
242242

243-
/// Returns the time in seconds since the unix epoch.
244-
pub fn abs_diff(&self, other: &Self) -> u64 {
245-
self.0.timestamp().abs_diff(other.0.timestamp())
243+
/// Returns the absolute difference between two datetimes as a `Duration`.
244+
pub fn duration_since(&self, other: &Self) -> Duration {
245+
let diff_secs = self.0.timestamp().abs_diff(other.0.timestamp());
246+
Duration::from_secs(diff_secs)
246247
}
247248

248249
/// Returns the time in seconds since the unix epoch.

lightning-liquidity/src/lsps5/service.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ where
145145
let should_prune = {
146146
let last_pruning = self.last_pruning.lock().unwrap();
147147
last_pruning.as_ref().map_or(true, |last_time| {
148-
now.abs_diff(&last_time) > PRUNE_STALE_WEBHOOKS_INTERVAL_DAYS.as_secs()
148+
now.duration_since(&last_time) > PRUNE_STALE_WEBHOOKS_INTERVAL_DAYS
149149
})
150150
};
151151

@@ -392,10 +392,9 @@ where
392392
if webhook
393393
.last_notification_sent
394394
.get(&notification.method)
395-
.map(|last_sent| now.clone().abs_diff(&last_sent))
396-
.map_or(true, |duration| {
397-
duration >= self.config.notification_cooldown_hours.as_secs()
398-
}) {
395+
.map(|last_sent| now.clone().duration_since(&last_sent))
396+
.map_or(true, |duration| duration >= self.config.notification_cooldown_hours)
397+
{
399398
webhook.last_notification_sent.insert(notification.method.clone(), now.clone());
400399
webhook.last_used = now.clone();
401400
self.send_notification(
@@ -462,7 +461,7 @@ where
462461
webhooks.retain(|client_id, client_webhooks| {
463462
if !self.client_has_open_channel(client_id) {
464463
client_webhooks.retain(|_, webhook| {
465-
now.abs_diff(&webhook.last_used) < MIN_WEBHOOK_RETENTION_DAYS.as_secs()
464+
now.duration_since(&webhook.last_used) < MIN_WEBHOOK_RETENTION_DAYS
466465
});
467466
!client_webhooks.is_empty()
468467
} else {

0 commit comments

Comments
 (0)