From 43832335b8e44e40683ffe6afa226a2d2de0d6ff Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 30 Mar 2024 17:47:21 -0700 Subject: [PATCH] timed: set valid flag (#32061) * timed: set valid flag * oops --- common/time.py | 13 +++++++++++-- system/timed.py | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/time.py b/common/time.py index f2e49eb5465bd7..5379faf22a81bd 100644 --- a/common/time.py +++ b/common/time.py @@ -1,6 +1,15 @@ import datetime +from pathlib import Path -MIN_DATE = datetime.datetime(year=2024, month=1, day=28) +_MIN_DATE = datetime.datetime(year=2024, month=3, day=30) + +def min_date(): + # on systemd systems, the default time is the systemd build time + systemd_path = Path("/lib/systemd/systemd") + if systemd_path.exists(): + d = datetime.datetime.fromtimestamp(systemd_path.stat().st_mtime) + return d + datetime.timedelta(days=1) + return _MIN_DATE def system_time_valid(): - return datetime.datetime.now() > MIN_DATE + return datetime.datetime.now() > min_date() diff --git a/system/timed.py b/system/timed.py index ab82f8c72d2b82..2b9a42c455154e 100755 --- a/system/timed.py +++ b/system/timed.py @@ -8,6 +8,7 @@ from timezonefinder import TimezoneFinder import cereal.messaging as messaging +from openpilot.common.time import system_time_valid from openpilot.common.params import Params from openpilot.common.swaglog import cloudlog from openpilot.system.hardware import AGNOS @@ -69,7 +70,8 @@ def main() -> NoReturn: while True: sm.update(1000) - msg = messaging.new_message('clocks', valid=True) + msg = messaging.new_message('clocks') + msg.valid = system_time_valid() msg.clocks.wallTimeNanos = time.time_ns() pm.send('clocks', msg)