-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update daily notification stats to use 12am utc #1976
Conversation
…ook starting at 12am UTC the night before
…12am utc the night before
if limit_days == 1: | ||
start_date = get_midnight(datetime.now(tz=pytz.utc)) | ||
else: | ||
start_date = midnight_n_days_ago(limit_days) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will return the correct datetime for the case we are trying to fix, but I think there are a couple issues with this change:
start_date
is a timezone aware datetime iflimit_days = 1
, and it is timezone naive iflimit_days > 1
. That makes the code harder to understand- the way
start_date
is calculated is very different iflimit_days = 1
vs iflimit_days > 1
. This might cause issues in the future when we forget this detail and we are calling the endpoint via notification-admin
Could we just always use utc midnight for this function? I'm thinking something like:
def utc_midnight_n_days_ago(number_of_days):
"""
Returns utc midnight a number of days ago.
"""
return get_midnight(datetime.utcnow() - timedelta(days=number_of_days))
in app/utils.py
, and then:
start_date = utc_midnight_n_days_ago(limit_days)
in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah for sure, I specifically targeted the 1 day case, but you make good points here. Let's chat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Summary | Résumé
This PR fixes the daily stats query to use midnight UTC which aligns with the way we handle daily limits.