From 69eee21faa4b567239393b7485cbc052a98a0026 Mon Sep 17 00:00:00 2001 From: Sebastian Aranda Sanchez Date: Thu, 19 Dec 2024 11:20:50 -0300 Subject: [PATCH] Convert narrativelog date_begin and date_end UTC datetimes to TAI to comply with the REST API definitions. --- manager/api/tests/test_ole.py | 4 ++-- manager/api/views.py | 21 +++++++++++++++++++++ manager/manager/utils.py | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/manager/api/tests/test_ole.py b/manager/api/tests/test_ole.py index 53c39054..8b7068b4 100644 --- a/manager/api/tests/test_ole.py +++ b/manager/api/tests/test_ole.py @@ -71,8 +71,8 @@ def setUp(self): "components": "MainTel", "primary_software_components": "None", "primary_hardware_components": "None", - "date_begin": "202200703-19:58:13", - "date_end": "20220704-19:25:13", + "date_begin": "2020-07-03T19:58:13.000000", + "date_end": "2022-07-04T19:25:13.000000", "time_lost": 10, "level": 0, } diff --git a/manager/api/views.py b/manager/api/views.py index 77b3e1d2..4814bb2f 100644 --- a/manager/api/views.py +++ b/manager/api/views.py @@ -70,6 +70,7 @@ get_jira_obs_report, get_obsday_from_tai, get_obsday_iso, + get_tai_from_utc, handle_jira_payload, send_smtp_email, upload_to_lfa, @@ -1307,6 +1308,16 @@ def create(self, request, *args, **kwargs): if "file[]" in json_data: del json_data["file[]"] + # Convert date_begin and date_end to TAI format + date_keys = { + "date_begin", + "date_end", + } + for key in date_keys: + if key in json_data: + tai_datetime = get_tai_from_utc(json_data[key]) + json_data[key] = tai_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f") + # Split lists of values separated by comma array_keys = { "components", @@ -1365,6 +1376,16 @@ def update(self, request, pk=None, *args, **kwargs): if "file[]" in json_data: del json_data["file[]"] + # Convert date_begin and date_end to TAI format + date_keys = { + "date_begin", + "date_end", + } + for key in date_keys: + if key in json_data: + tai_datetime = get_tai_from_utc(json_data[key]) + json_data[key] = tai_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f") + array_keys = { "components", "primary_software_components", diff --git a/manager/manager/utils.py b/manager/manager/utils.py index b36ee1c3..b470d2fe 100644 --- a/manager/manager/utils.py +++ b/manager/manager/utils.py @@ -833,6 +833,22 @@ def get_tai_to_utc() -> float: return dt +def get_tai_from_utc(utc): + """Return the TAI timestamp from an UTC timestamp. + + Parameters + ---------- + utc : `datetime.datetime` + UTC timestamp + + Returns + ------- + `datetime.datetime` + The TAI timestamp + """ + return Time(utc, scale="utc").tai.datetime + + def get_times(): """Return relevant time measures.