Skip to content

Commit

Permalink
Add utc_yesterday helper to figures.helpers
Browse files Browse the repository at this point in the history
This is a convenience function to get the previous calendar day from th
ecurrent UTC time. This is the date for which the pipeline uses to
collect, save data and aggregate metrics for the daily jobs
  • Loading branch information
johnbaldwin committed Feb 24, 2022
1 parent 83687ca commit 42ce02d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion figures/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Helper functions to make data handling and conversions easier
# Figures 0.3.13 - Defining scope of this module
# Figures 0.4.x - Yep, this module is still handy and the scope hasn't exploded
The purpose of this module is to provide conveniece methods around commonly
executed statements. These convenience methods should serve as shorthand for
Expand Down Expand Up @@ -34,6 +35,8 @@
## What does not belong here?
* Most importantly, if you have to import from another figures module, it does
not belong here!
* "Feature" functionality does not belong here
* Long functions do not belong here
* Code that communicates outside of Figures does not belong here. No database,
Expand All @@ -42,7 +45,10 @@
This is not an exhaustive list. We'll grow it as needed.
An important point is that we should not expect this module to be a permanent
home for functionality.
home for the functionality included. As we evolve Figures, we may find functions
here that have a stronger context with another module. For example, we've got
a decent set of date oriented functions that are candidatdes for a datetime and
date handling module.
"""

from __future__ import absolute_import
Expand Down Expand Up @@ -188,6 +194,15 @@ def prev_day(val):
return days_from(val, -1)


def utc_yesterday():
"""Get "yesterday" form the utc datetime
We primarily use this for the daily metrics collection. However, it proves
handy as a convenience function for exploring data in the Django shell
"""
return prev_day(datetime.datetime.utcnow().date())


def days_in_month(month_for):
_, num_days_in_month = calendar.monthrange(month_for.year, month_for.month)
return num_days_in_month
Expand Down

0 comments on commit 42ce02d

Please sign in to comment.