Skip to content
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

Merged
merged 9 commits into from
Sep 14, 2023

Conversation

andrewleith
Copy link
Member

Summary | Résumé

This PR fixes the daily stats query to use midnight UTC which aligns with the way we handle daily limits.

Comment on lines 244 to 247
if limit_days == 1:
start_date = get_midnight(datetime.now(tz=pytz.utc))
else:
start_date = midnight_n_days_ago(limit_days)
Copy link
Contributor

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 if limit_days = 1, and it is timezone naive if limit_days > 1. That makes the code harder to understand
  • the way start_date is calculated is very different if limit_days = 1 vs if limit_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.

Copy link
Member Author

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!

Copy link
Contributor

@smcmurtry smcmurtry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@andrewleith andrewleith merged commit da75e8e into main Sep 14, 2023
@andrewleith andrewleith deleted the fix/update-daily-stats-query branch September 14, 2023 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants