Skip to content
Snippets Groups Projects
Commit 790bef4d authored by Hannes Feldt's avatar Hannes Feldt
Browse files

Fix datetime issue

parent cab89305
Branches
Tags
1 merge request!1070Fix datetime issue
# Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy)
# Copyright (C) 2025 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
from datetime import datetime
from datetime import datetime, timezone
import logging
from typing import Callable, Type
......@@ -87,10 +87,12 @@ class ObservationController(dict[int, Observation]):
# Check further properties that cannot be validated through a JSON schema
# TODO(Corne): Discuss do we want this?
for observation_field_settings in settings.antenna_fields:
if (
datetime.fromisoformat(observation_field_settings.stop_time)
<= datetime.now()
):
start = datetime.fromisoformat(observation_field_settings.stop_time)
if not start.tzinfo:
start = start.replace(tzinfo=timezone.utc)
if start <= datetime.now(timezone.utc):
raise ValueError(
"Cannot start observation "
f"{observation_field_settings.observation_id} because antenna "
......
# Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy)
# Copyright (C) 2025 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
import copy
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Dict
from typing import List
from unittest import mock
......@@ -128,7 +128,9 @@ class TestObservationController(base.TestCase):
def test_add_observation(self, _m_tango_util):
settings = get_observation_settings_two_fields_core()
for antenna_field in settings.antenna_fields:
antenna_field.stop_time = (datetime.now() + timedelta(days=1)).isoformat()
antenna_field.stop_time = (
datetime.now(timezone.utc) + timedelta(days=1)
).isoformat()
sut = obs_module.ObservationController("DMR")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment