Skip to content

Commit 5e41869

Browse files
committed
utc timezone fix
1 parent 3015313 commit 5e41869

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

axis-ptz-controller/axis_ptz_controller.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import ast
8-
from datetime import datetime
8+
from datetime import datetime, timezone
99
import json
1010
from json import JSONDecodeError
1111

@@ -296,7 +296,7 @@ def __init__(
296296
self.object: Object = Object("fake", self.camera) # Initialize with a fake object for Typing
297297

298298
config_msg = self.generate_payload_json(
299-
push_timestamp=int(datetime.utcnow().timestamp()),
299+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
300300
device_type=os.environ.get("DEVICE_TYPE", "Collector"),
301301
id_=self.hostname,
302302
deployment_id=os.environ.get(
@@ -328,7 +328,7 @@ def __init__(
328328
# coordinate system to the camera housing fixed (uvw)
329329
# coordinate system
330330
orientation_msg = self.generate_payload_json(
331-
push_timestamp=int(datetime.utcnow().timestamp()),
331+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
332332
device_type=os.environ.get("DEVICE_TYPE", "Collector"),
333333
id_=self.hostname,
334334
deployment_id=os.environ.get(
@@ -589,7 +589,7 @@ def _config_object(self) -> Dict[str, Any]:
589589
def _publish_config(self) -> None:
590590
config = self._config_object()
591591
config_msg = self.generate_payload_json(
592-
push_timestamp=int(datetime.utcnow().timestamp()),
592+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
593593
device_type=os.environ.get("DEVICE_TYPE", "Collector"),
594594
id_=self.hostname,
595595
deployment_id=os.environ.get(
@@ -746,7 +746,7 @@ def _track_object(self, time_since_last_update: float) -> None:
746746
# Log camera pointing using MQTT
747747
if self.log_to_mqtt:
748748
logger_msg = self.generate_payload_json(
749-
push_timestamp=int(datetime.utcnow().timestamp()),
749+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
750750
device_type=os.environ.get("DEVICE_TYPE", "Collector"),
751751
id_=self.hostname,
752752
deployment_id=os.environ.get(
@@ -996,7 +996,7 @@ def _send_data(self, data: Dict[str, str]) -> bool:
996996
"""
997997
# Generate payload as JSON
998998
payload = self.generate_payload_json(
999-
push_timestamp=int(datetime.utcnow().timestamp()),
999+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
10001000
device_type=os.environ.get("DEVICE_TYPE", "Collector"),
10011001
id_=self.hostname,
10021002
deployment_id=os.environ.get(
@@ -1088,7 +1088,6 @@ def _capture_image(self) -> None:
10881088
)
10891089

10901090
ptz_age = time() - ptz_time
1091-
logging.info(f"PTZ time: {ptz_age}")
10921091
adjusted_rho_c = rho_c + self.rho_dot_c * self.capture_lead_time
10931092
adjusted_tau_c = tau_c + self.tau_dot_c * self.capture_lead_time
10941093
# Note: this time does not include any leading

axis-ptz-controller/axis_ptz_utilities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import base64
22
import contextlib
3-
from datetime import datetime
3+
from datetime import datetime, timezone
44
import logging
55
import math
66
import os

axis-ptz-controller/object.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
import axis_ptz_utilities
88
from camera import Camera
9-
9+
from datetime import datetime, timezone
1010

1111
class Object:
1212

@@ -184,8 +184,8 @@ def recompute_location(self) -> None:
184184
msg_age = 0.0
185185
if self.include_age:
186186
msg_age = (
187-
time() - self.msg_timestamp
188-
) # datetime.utcnow().timestamp() - self.timestamp_o # [s]
187+
datetime.now(timezone.utc).timestamp() - self.msg_timestamp
188+
) # datetime.now(timezone.utc).timestamp() - self.timestamp_o # [s]
189189
logging.debug(f"Object msg age: {msg_age} [s]")
190190
if msg_age < 0:
191191
logging.warning(

tests/test_modules.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, timezone
22
import json
33
import math
44
import os
@@ -100,7 +100,7 @@ def config_msg(controller: axis_ptz_controller.AxisPtzController) -> str:
100100
with open("test-data/unit-test-data/config_msg_data.json", "r") as f:
101101
data = json.load(f)
102102
msg = controller.generate_payload_json(
103-
push_timestamp=int(datetime.utcnow().timestamp()),
103+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
104104
device_type="TBC",
105105
id_="TBC",
106106
deployment_id="TBC",
@@ -121,7 +121,7 @@ def orientation_msg_0s(controller: axis_ptz_controller.AxisPtzController) -> str
121121
with open("test-data/unit-test-data/orientation_msg_data_0s.json", "r") as f:
122122
data = json.load(f)
123123
msg = controller.generate_payload_json(
124-
push_timestamp=int(datetime.utcnow().timestamp()),
124+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
125125
device_type="TBC",
126126
id_="TBC",
127127
deployment_id="TBC",
@@ -142,7 +142,7 @@ def orientation_msg_90s(controller: axis_ptz_controller.AxisPtzController) -> st
142142
with open("test-data/unit-test-data/orientation_msg_data_90s.json", "r") as f:
143143
data = json.load(f)
144144
msg = controller.generate_payload_json(
145-
push_timestamp=int(datetime.utcnow().timestamp()),
145+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
146146
device_type="TBC",
147147
id_="TBC",
148148
deployment_id="TBC",
@@ -175,7 +175,7 @@ def object_msg(controller: axis_ptz_controller.AxisPtzController) -> str:
175175
with open("test-data/unit-test-data/object_msg_data.json", "r") as f:
176176
data = json.load(f)
177177
msg = controller.generate_payload_json(
178-
push_timestamp=int(datetime.utcnow().timestamp()),
178+
push_timestamp=int(datetime.now(timezone.utc).timestamp()),
179179
device_type="TBC",
180180
id_="TBC",
181181
deployment_id="TBC",

0 commit comments

Comments
 (0)