Skip to content

Commit

Permalink
Fix test_clockTest clock
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Oct 24, 2023
1 parent 8ded380 commit 865bc92
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/yaroc/utils/sim7020.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shlex
import subprocess
import time
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Callable

from ..pb.status_pb2 import Disconnected, Status
Expand Down Expand Up @@ -119,7 +119,7 @@ def mqtt_connect(self):
self._mqtt_id_timestamp = datetime.now()

def set_clock(self, modem_clock: str):
tim = is_time_off(modem_clock, datetime.now())
tim = is_time_off(modem_clock, datetime.now(timezone.utc))
if tim is not None:
subprocess.call(shlex.split(f"sudo -n date -s '{tim.isoformat()}'"))

Expand Down
5 changes: 3 additions & 2 deletions src/yaroc/utils/sys_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ def create_sys_minicallhome() -> MiniCallHome:


def is_time_off(modem_clock: str, now: datetime) -> datetime | None:
# assert now.tzinfo == timezone.utc
try:
tim = (
datetime.strptime(modem_clock[:20], "%y/%m/%d,%H:%M:%S+08")
.replace(tzinfo=timezone.utc)
.astimezone()
)
if tim - now.astimezone() > timedelta(seconds=5):
print(tim, now)
if tim - now > timedelta(seconds=5):
return tim
return None
except Exception as err:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from yaroc.utils.sys_info import is_time_off


class TestMeos(unittest.TestCase):
class TestClock(unittest.TestCase):
def test_competitor_parsing(self):
modem_clock = "23/06/09,12:06:31+08"
now = datetime(2023, 6, 9, 14, 6, 25)
Expand Down

0 comments on commit 865bc92

Please sign in to comment.