-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicense_utils.py
More file actions
46 lines (34 loc) · 1.3 KB
/
Copy pathlicense_utils.py
File metadata and controls
46 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
License utility functions for expiry and validation logic.
"""
import math
import time
from typing import Optional
def compute_days_until_expiry(expiry_timestamp: float, now: float = None) -> Optional[int]:
"""Compute the number of days remaining until the license expires.
Args:
expiry_timestamp: The Unix timestamp when the license expires.
now: Optional override for the current time (used for testing).
Returns:
The number of full days remaining, or None if the license never expires.
Expired licenses return a negative value (e.g., -1 for anything < 0).
"""
if expiry_timestamp <= 0:
return None # Community/Never expires
if now is None:
now = time.time()
remaining = expiry_timestamp - now
return math.floor(remaining / 86400)
def is_expired(expiry_timestamp: float, now: float = None) -> bool:
"""Check if a license has expired.
Args:
expiry_timestamp: The Unix timestamp when the license expires.
now: Optional override for the current time (used for testing).
Returns:
True if the current time is past the expiry timestamp.
"""
if expiry_timestamp <= 0:
return False # Community/Never expires
if now is None:
now = time.time()
return now > expiry_timestamp