Skip to content

Commit

Permalink
Fix small bug when passing NOTIFICATION_FREQUENCY.INSTANT without sta…
Browse files Browse the repository at this point in the history
…rt_time
  • Loading branch information
IonesioJunior committed Sep 23, 2024
1 parent 2f9b2a9 commit f88c6e6
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions packages/syft/src/syft/service/notifier/notifier_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,27 @@ def set_email_batch(
"If frequency isn't INSTANT, you must set a start time for the notifications to be dispatched."
)

start_time = start_time.lower()
try:
if "pm" in start_time or "am" in start_time:
time_obj = datetime.strptime(start_time, "%I:%M %p")
else:
time_obj = datetime.strptime(start_time, "%H:%M")
except ValueError:
raise SyftException(
"Invalid time format."
+ "Please enter the start time in one of the following format examples:"
+ "'14:00' or '2:00 PM'."
)
if frequency is not NOTIFICATION_FREQUENCY.INSTANT:
start_time = start_time.lower()
try:
if "pm" in start_time or "am" in start_time:
time_obj = datetime.strptime(start_time, "%I:%M %p")
else:
time_obj = datetime.strptime(start_time, "%H:%M")
except ValueError:
raise SyftException(
"Invalid time format."
+ "Please enter the start time in one of the following format examples:"
+ "'14:00' or '2:00 PM'."
)
else:
time_obj = datetime.now()

notifier = self.stash.get(credentials=context.credentials).unwrap()
notifier.email_frequency[email_type.value] = EmailFrequency(
frequency=frequency, start_time=time_obj
)
self.stash.update(
credentials=context.credentials, obj=notifier
).unwrap()
self.stash.update(credentials=context.credentials, obj=notifier).unwrap()
return SyftSuccess(message="Configuration set successfully.")

@as_result(StashException)
Expand Down Expand Up @@ -283,9 +285,6 @@ def is_time_to_dispatch(
period = timedelta(days=1)
elif frequency == NOTIFICATION_FREQUENCY.WEEKLY:
period = timedelta(weeks=1)
else:
# Unknown frequency
return False

# Calculate how many full periods have passed since start_time
elapsed_time = current_time - start_time
Expand Down

0 comments on commit f88c6e6

Please sign in to comment.