slightly more robust time validity check

notmaster
Adeeb Shihadeh 2 months ago
parent 839c8fbd6b
commit 9881cf9c20
  1. 6
      common/time_helpers.py

@ -1,15 +1,15 @@
import datetime import datetime
from pathlib import Path from pathlib import Path
_MIN_DATE = datetime.datetime(year=2024, month=8, day=26) MIN_DATE = datetime.datetime(year=2025, month=2, day=21)
def min_date(): def min_date():
# on systemd systems, the default time is the systemd build time # on systemd systems, the default time is the systemd build time
systemd_path = Path("/lib/systemd/systemd") systemd_path = Path("/lib/systemd/systemd")
if systemd_path.exists(): if systemd_path.exists():
d = datetime.datetime.fromtimestamp(systemd_path.stat().st_mtime) d = datetime.datetime.fromtimestamp(systemd_path.stat().st_mtime)
return d + datetime.timedelta(days=1) return max(MIN_DATE, d + datetime.timedelta(days=1))
return _MIN_DATE return MIN_DATE
def system_time_valid(): def system_time_valid():
return datetime.datetime.now() > min_date() return datetime.datetime.now() > min_date()

Loading…
Cancel
Save