Skip to content

Commit

Permalink
Convert narrativelog date_begin and date_end UTC datetimes to TAI to …
Browse files Browse the repository at this point in the history
…comply with the REST API definitions.
  • Loading branch information
sebastian-aranda committed Dec 20, 2024
1 parent ff449c5 commit 69eee21
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions manager/api/tests/test_ole.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
21 changes: 21 additions & 0 deletions manager/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 69eee21

Please sign in to comment.