Skip to content

Commit

Permalink
Merge pull request #585 from mjefferys/fix-nwleics-todaytomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
robbrad authored Jan 18, 2024
2 parents 824141d + 15b6196 commit 58cdf86
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,23 @@ def parse_data(self, page: str, **kwargs) -> dict:

# Parse the date from the string
# check for today and tomorrow
if date.lower() == 'today':
parsed_date = datetime.now().strftime("%a %d %b")
if date.lower() == 'today':
parsed_date = datetime.now().date()
elif date.lower() == 'tomorrow':
parsed_date = (datetime.now() + timedelta(days=1)).strftime("%a %d %b")
parsed_date = (datetime.now() + timedelta(days=1)).date()
else:
date = re.sub(r"(st|nd|rd|th)", "", date)
parsed_date = datetime.strptime(date, "%a %d %b")
parsed_date = datetime.strptime(date, "%a %d %b").date()

if parsed_date < datetime(
parsed_date.year, parsed_date.month, parsed_date.day
):
parsed_date = parsed_date.replace(year=current_year + 1)
else:
parsed_date = parsed_date.replace(year=current_year)
current_date = datetime.now().date()

# double check we've got a year and if not the current one
if parsed_date.year < current_date.year:
parsed_date = parsed_date.replace(year=current_date.year)

# check if the date is in the past and if so add a year
if parsed_date < current_date:
parsed_date = parsed_date.replace(year=current_date.year + 1)

# Append data to your 'bins' list (this replicates your existing logic)
data["bins"].append(
Expand Down

0 comments on commit 58cdf86

Please sign in to comment.