Skip to content

Commit

Permalink
Ensure on_end makes input tz aware
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGarbutt committed Sep 4, 2024
1 parent 6f60577 commit ed335e0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions coral_credits/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,14 @@ def on_end(self, request):
# We can't just set everything to current time as we don't know
# the latency between blazars request and our reception.
# Unless we decide on how to round credit allocations.
if (
datetime.fromisoformat(request.data["lease"]["start_date"])
< time_now
):
request.data["lease"]["end_date"] = request.data["lease"][
"start_date"
]
req_start_date = datetime.fromisoformat(
request.data["lease"]["start_date"]
)
if req_start_date.tzinfo is None:
req_start_date = make_aware(req_start_date)
if req_start_date < time_now:
# TODO(johngarbutt) we need to check what we have in the db!
request.data["lease"]["end_date"] = req_start_date.isoformat()
else:
request.data["lease"]["end_date"] = time_now.isoformat()
return self._create_or_update(
Expand Down

0 comments on commit ed335e0

Please sign in to comment.