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 19, 2024
1 parent 02d2c65 commit cc4326d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
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 cc4326d

Please sign in to comment.