put timezone dt in config

This commit is contained in:
stvnrlly
2022-11-29 10:58:59 -05:00
parent 219dc7b2ec
commit 446694d1cc
4 changed files with 9 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import json import json
import os import os
import pytz
from app.cloudfoundry_config import cloud_config from app.cloudfoundry_config import cloud_config
@@ -13,6 +14,7 @@ class Config(object):
LOGO_CDN_DOMAIN = 'static-logos.notifications.service.gov.uk' # TODO use our own CDN LOGO_CDN_DOMAIN = 'static-logos.notifications.service.gov.uk' # TODO use our own CDN
ASSETS_DEBUG = False ASSETS_DEBUG = False
TIMEZONE = os.environ.get('TIMEZONE', 'America/New_York') TIMEZONE = os.environ.get('TIMEZONE', 'America/New_York')
PY_TIMEZONE = pytz.timezone(TIMEZONE)
# Credentials # Credentials
ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET') ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET')

View File

@@ -77,8 +77,8 @@ def get_time_value_and_label(future_time):
return ( return (
future_time.replace(tzinfo=None).isoformat(), future_time.replace(tzinfo=None).isoformat(),
'{} at {} ET'.format( '{} at {} ET'.format(
get_human_day(future_time.astimezone(pytz.timezone(current_app.config['TIMEZONE']))), get_human_day(future_time.astimezone(current_app.config['PY_TIMEZONE'])),
get_human_time(future_time.astimezone(pytz.timezone(current_app.config['TIMEZONE']))) get_human_time(future_time.astimezone(current_app.config['PY_TIMEZONE']))
) )
) )

View File

@@ -13,8 +13,8 @@ from app.main import main
@main.route("/performance") @main.route("/performance")
def performance(): def performance():
stats = performance_dashboard_api_client.get_performance_dashboard_stats( stats = performance_dashboard_api_client.get_performance_dashboard_stats(
start_date=(datetime.now(pytz.timezone(current_app.config['TIMEZONE'])) - timedelta(days=7)).date(), start_date=(datetime.now(current_app.config['PY_TIMEZONE']) - timedelta(days=7)).date(),
end_date=datetime.now(pytz.timezone(current_app.config['TIMEZONE'])).date(), end_date=datetime.now(current_app.config['PY_TIMEZONE']).date(),
) )
stats['organisations_using_notify'] = sorted( stats['organisations_using_notify'] = sorted(
[ [

View File

@@ -4,11 +4,11 @@ import pytz
from dateutil import parser from dateutil import parser
from notifications_utils.timezones import convert_utc_to_local_timezone from notifications_utils.timezones import convert_utc_to_local_timezone
from flask import current_app
def get_current_financial_year(): def get_current_financial_year():
now = convert_utc_to_local_timezone( now = datetime.now(current_app.config['PY_TIMEZONE'])
datetime.utcnow()
)
current_month = int(now.strftime('%-m')) current_month = int(now.strftime('%-m'))
current_year = int(now.strftime('%Y')) current_year = int(now.strftime('%Y'))
return current_year if current_month > 3 else current_year - 1 return current_year if current_month > 3 else current_year - 1