Skip to content

Commit

Permalink
get_date optimised
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Golfari committed Jun 20, 2023
1 parent 281ad39 commit 3bff2a7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions airscore/core/calcUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ def get_datetime(t):
return t


def get_date(t):
def get_date(t) -> datetime.date or any:
"""
Transform string in datetime.date
Gets first 10 positions in string ('YYYY-mm-dd')
It should work with any separator
"""
try:
return datetime.strptime(t[:10], '%Y-%m-%d').date()
except (ValueError, TypeError) as e:
d = t[:10]
s = d[4]
f = f"%Y{s}%m{s}%d"
return datetime.strptime(d, f).date()
except (ValueError, TypeError, IndexError) as e:
return t


Expand Down

0 comments on commit 3bff2a7

Please sign in to comment.