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

Merge branch 'fix-datetime-issue' into 'master'

Fix datetime issue

See merge request !1070
parents cab89305 790bef4d
No related branches found
No related tags found
1 merge request!1070Fix datetime issue
Pipeline #112732 failed
Pipeline: tango

#112734

    # Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy) # Copyright (C) 2025 ASTRON (Netherlands Institute for Radio Astronomy)
    # SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
    from datetime import datetime from datetime import datetime, timezone
    import logging import logging
    from typing import Callable, Type from typing import Callable, Type
    ...@@ -87,10 +87,12 @@ class ObservationController(dict[int, Observation]): ...@@ -87,10 +87,12 @@ class ObservationController(dict[int, Observation]):
    # Check further properties that cannot be validated through a JSON schema # Check further properties that cannot be validated through a JSON schema
    # TODO(Corne): Discuss do we want this? # TODO(Corne): Discuss do we want this?
    for observation_field_settings in settings.antenna_fields: for observation_field_settings in settings.antenna_fields:
    if ( start = datetime.fromisoformat(observation_field_settings.stop_time)
    datetime.fromisoformat(observation_field_settings.stop_time)
    <= datetime.now() if not start.tzinfo:
    ): start = start.replace(tzinfo=timezone.utc)
    if start <= datetime.now(timezone.utc):
    raise ValueError( raise ValueError(
    "Cannot start observation " "Cannot start observation "
    f"{observation_field_settings.observation_id} because antenna " 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 # SPDX-License-Identifier: Apache-2.0
    import copy import copy
    from datetime import datetime, timedelta from datetime import datetime, timedelta, timezone
    from typing import Dict from typing import Dict
    from typing import List from typing import List
    from unittest import mock from unittest import mock
    ...@@ -128,7 +128,9 @@ class TestObservationController(base.TestCase): ...@@ -128,7 +128,9 @@ class TestObservationController(base.TestCase):
    def test_add_observation(self, _m_tango_util): def test_add_observation(self, _m_tango_util):
    settings = get_observation_settings_two_fields_core() settings = get_observation_settings_two_fields_core()
    for antenna_field in settings.antenna_fields: 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") 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