diff --git a/bolt11/types.py b/bolt11/types.py index d90ad98..c93cd84 100644 --- a/bolt11/types.py +++ b/bolt11/types.py @@ -107,6 +107,12 @@ def expiry(self) -> Optional[int]: tag = self.tags.get(TagChar.expire_time) return tag.data if tag else None + @property + def expiry_date(self) -> Optional[datetime]: + if not self.expiry: + return None + return datetime.fromtimestamp(self.date + self.expiry) + @property def features(self) -> Optional[Features]: tag = self.tags.get(TagChar.features) diff --git a/tests/test_bolt11_examples.py b/tests/test_bolt11_examples.py index 9a84174..d42613f 100644 --- a/tests/test_bolt11_examples.py +++ b/tests/test_bolt11_examples.py @@ -1,3 +1,5 @@ +from datetime import datetime + from bolt11.decode import decode from bolt11.encode import encode from bolt11.models.fallback import Fallback @@ -127,7 +129,9 @@ def test_example_2(self): decoded = decode(ex["payment_request"]) assert decoded.currency == ex["currency"] assert decoded.date == ex["date"] + assert decoded.dt == datetime.fromtimestamp(ex["date"]) assert decoded.expiry == ex["expiry"] + assert decoded.expiry_date == datetime.fromtimestamp(ex["date"] + ex["expiry"]) assert decoded.payment_hash == ex["payment_hash"] assert decoded.payment_secret == ex["payment_secret"] assert decoded.amount_msat == ex["amount_msat"]