mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
moved generate_date_range to date_util
standardized the SQLAlchemy calls refactored the endpoints in service/rest.py
This commit is contained in:
@@ -71,3 +71,25 @@ def get_calendar_year_for_datetime(start_date):
|
||||
|
||||
def get_number_of_days_for_month(year, month):
|
||||
return calendar.monthrange(year, month)[1]
|
||||
|
||||
|
||||
def generate_date_range(start_date, end_date=None, days=0):
|
||||
if end_date:
|
||||
current_date = start_date
|
||||
while current_date <= end_date:
|
||||
try:
|
||||
yield current_date.date()
|
||||
except ValueError:
|
||||
pass
|
||||
current_date += timedelta(days=1)
|
||||
elif days > 0:
|
||||
end_date = start_date + timedelta(days=days)
|
||||
current_date = start_date
|
||||
while current_date < end_date:
|
||||
try:
|
||||
yield current_date.date()
|
||||
except ValueError:
|
||||
pass
|
||||
current_date += timedelta(days=1)
|
||||
else:
|
||||
return "A start_date or number of days must be specified"
|
||||
|
||||
@@ -427,9 +427,9 @@ def dao_fetch_todays_stats_for_service(service_id):
|
||||
)
|
||||
|
||||
|
||||
def dao_fetch_stats_for_service_from_days(service_id, start, days):
|
||||
start_date = get_midnight_in_utc(start)
|
||||
end_date = get_midnight_in_utc(start + timedelta(days=days))
|
||||
def dao_fetch_stats_for_service_from_days(service_id, start_date, end_date):
|
||||
start_date = get_midnight_in_utc(start_date)
|
||||
end_date = get_midnight_in_utc(end_date)
|
||||
|
||||
return (
|
||||
db.session.query(
|
||||
@@ -453,9 +453,11 @@ def dao_fetch_stats_for_service_from_days(service_id, start, days):
|
||||
)
|
||||
|
||||
|
||||
def dao_fetch_stats_for_service_from_days_for_user(service_id, start, days, user_id):
|
||||
start_date = get_midnight_in_utc(start)
|
||||
end_date = get_midnight_in_utc(start + timedelta(days=days))
|
||||
def dao_fetch_stats_for_service_from_days_for_user(
|
||||
service_id, start_date, end_date, user_id
|
||||
):
|
||||
start_date = get_midnight_in_utc(start_date)
|
||||
end_date = get_midnight_in_utc(end_date)
|
||||
|
||||
return (
|
||||
db.session.query(
|
||||
|
||||
Reference in New Issue
Block a user