Skip to content

Commit

Permalink
update date math
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahgibs committed May 20, 2024
1 parent b413add commit 9f67c03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
30 changes: 13 additions & 17 deletions zap/src/drive_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,22 @@ def upload_file_to_drive(filename, folder_id, drive_id, drive):
supportsAllDrives=True).execute()
return file

def after_final_wednesday(date):
def after_fourth_wednesday(date):
"""
Returns true if is the last Wednesday of the month or later.
The exception is when the last day of the month falls on a Wedensday,
in that case it returns true if it is on or after the second to last
Wednesday of the month.
Returns true if is the fourth Wednesday of the month or later.
"""
_,day_count = calendar.monthrange(date.year, date.month)
working_weekday = date.weekday()
working_day = date.day
offset = (working_weekday - WEDNESDAY) % 7
last_wednesday = date - timedelta(days=offset)
diff = day_count - working_day
# If it's not the last week of the month, return False.
if diff > 7:
current_weekday = date.weekday()
current_day = date.day
offset = (current_weekday - WEDNESDAY) % 7
previous_wednesday = date - timedelta(days=offset)
# How far from the end of the month are we.
diff = day_count - current_day
# If it's not the last ten days of the month, return False.
if diff > (day_count-21):
return False
diff = day_count - last_wednesday.day
# If the last day of the month is wednesday, add a week to the check.
if diff == 0:
diff = 6
if diff <= 7:
# The earliest day the 4th wednesday can be is the 22nd.
diff = previous_wednesday.day - 21
if diff > 0:
return True
return False
2 changes: 1 addition & 1 deletion zap/src/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def main(): # pylint: disable=too-many-locals
if not folder_structure:
raise RuntimeError("The provided gdrive folder ID was not found.")
date = datetime.today()
if drivehelper.after_final_wednesday(date):
if drivehelper.after_fourth_wednesday(date):
date = date + timedelta(days=10)

logging.info("Finding the folders for this month's scans in Google Drive")
Expand Down

0 comments on commit 9f67c03

Please sign in to comment.