Skip to content

Commit cc4326d

Browse files
Convert narrativelog date_begin and date_end UTC datetimes to TAI to comply with the REST API definitions.
1 parent 02d2c65 commit cc4326d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

manager/api/views.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
get_jira_obs_report,
7171
get_obsday_from_tai,
7272
get_obsday_iso,
73+
get_tai_from_utc,
7374
handle_jira_payload,
7475
send_smtp_email,
7576
upload_to_lfa,
@@ -1307,6 +1308,16 @@ def create(self, request, *args, **kwargs):
13071308
if "file[]" in json_data:
13081309
del json_data["file[]"]
13091310

1311+
# Convert date_begin and date_end to TAI format
1312+
date_keys = {
1313+
"date_begin",
1314+
"date_end",
1315+
}
1316+
for key in date_keys:
1317+
if key in json_data:
1318+
tai_datetime = get_tai_from_utc(json_data[key])
1319+
json_data[key] = tai_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")
1320+
13101321
# Split lists of values separated by comma
13111322
array_keys = {
13121323
"components",
@@ -1365,6 +1376,16 @@ def update(self, request, pk=None, *args, **kwargs):
13651376
if "file[]" in json_data:
13661377
del json_data["file[]"]
13671378

1379+
# Convert date_begin and date_end to TAI format
1380+
date_keys = {
1381+
"date_begin",
1382+
"date_end",
1383+
}
1384+
for key in date_keys:
1385+
if key in json_data:
1386+
tai_datetime = get_tai_from_utc(json_data[key])
1387+
json_data[key] = tai_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")
1388+
13681389
array_keys = {
13691390
"components",
13701391
"primary_software_components",

manager/manager/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,22 @@ def get_tai_to_utc() -> float:
833833
return dt
834834

835835

836+
def get_tai_from_utc(utc):
837+
"""Return the TAI timestamp from an UTC timestamp.
838+
839+
Parameters
840+
----------
841+
utc : `datetime.datetime`
842+
UTC timestamp
843+
844+
Returns
845+
-------
846+
`datetime.datetime`
847+
The TAI timestamp
848+
"""
849+
return Time(utc, scale="utc").tai.datetime
850+
851+
836852
def get_times():
837853
"""Return relevant time measures.
838854

0 commit comments

Comments
 (0)