Skip to content

Commit

Permalink
Correct wrong month
Browse files Browse the repository at this point in the history
  • Loading branch information
Meisterschueler committed Apr 5, 2021
1 parent 8fef358 commit edc4702
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ogn/parser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ def createTimestamp(time_string, reference_timestamp):
hh, mm, 0,
tzinfo=timezone.utc if reference_timestamp.tzinfo is not None else None)

# correct wrong month
if result > reference_timestamp + timedelta(days=14):
# shift timestamp to previous month
result = (result.replace(day=1) - timedelta(days=5)).replace(day=result.day)
result = (result.replace(day=1) - timedelta(days=14)).replace(day=result.day)
elif result < reference_timestamp - timedelta(days=14):
# shift timestamp to next month
result = (result.replace(day=28) + timedelta(days=5)).replace(day=result.day)
result = (result.replace(day=28) + timedelta(days=14)).replace(day=result.day)
else:
hh = int(time_string[0:2])
mm = int(time_string[2:4])
Expand Down

0 comments on commit edc4702

Please sign in to comment.