diff --git a/app/commands.py b/app/commands.py index 3af2e566b2..b46d614477 100644 --- a/app/commands.py +++ b/app/commands.py @@ -350,7 +350,7 @@ def migrate_data_to_ft_billing( from ( select n.id, - (n.created_at at time zone 'UTC' at time zone 'America/Toronto')::timestamp::date as bst_date, + (n.created_at at time zone 'UTC' at time zone 'America/New_York')::timestamp::date as bst_date, coalesce(n.template_id, '00000000-0000-0000-0000-000000000000') as template_id, coalesce(n.service_id, '00000000-0000-0000-0000-000000000000') as service_id, n.notification_type, @@ -382,9 +382,9 @@ def migrate_data_to_ft_billing( where n.key_type!='test' and n.notification_status in ('sending', 'sent', 'delivered', 'temporary-failure', 'permanent-failure', 'failed') - and n.created_at >= (date :start + time '00:00:00') at time zone 'America/Toronto' + and n.created_at >= (date :start + time '00:00:00') at time zone 'America/New_York' at time zone 'UTC' - and n.created_at < (date :end + time '00:00:00') at time zone 'America/Toronto' at time zone 'UTC' + and n.created_at < (date :end + time '00:00:00') at time zone 'America/New_York' at time zone 'UTC' ) as individual_record group by bst_date, template_id, service_id, notification_type, provider, rate_multiplier, international, sms_rate, letter_rate, postage, created_at @@ -477,7 +477,7 @@ def migrate_data_to_ft_notification_status( insert into ft_notification_status (bst_date, template_id, service_id, job_id, notification_type, key_type, notification_status, created_at, notification_count) select - (n.created_at at time zone 'UTC' at time zone 'America/Toronto')::timestamp::date as bst_date, + (n.created_at at time zone 'UTC' at time zone 'America/New_York')::timestamp::date as bst_date, coalesce(n.template_id, '00000000-0000-0000-0000-000000000000') as template_id, n.service_id, coalesce(n.job_id, '00000000-0000-0000-0000-000000000000') as job_id, @@ -487,8 +487,8 @@ def migrate_data_to_ft_notification_status( now() as created_at, count(*) as notification_count from notification_history n - where n.created_at >= (date :start + time '00:00:00') at time zone 'America/Toronto' at time zone 'UTC' - and n.created_at < (date :end + time '00:00:00') at time zone 'America/Toronto' at time zone 'UTC' + where n.created_at >= (date :start + time '00:00:00') at time zone 'America/New_York' at time zone 'UTC' + and n.created_at < (date :end + time '00:00:00') at time zone 'America/New_York' at time zone 'UTC' group by bst_date, template_id, service_id, job_id, notification_type, key_type, notification_status order by bst_date """ @@ -626,9 +626,9 @@ def update_jobs_archived_flag( sql = """update jobs set archived = true where - created_at >= (date :start + time '00:00:00') at time zone 'America/Toronto' + created_at >= (date :start + time '00:00:00') at time zone 'America/New_York' at time zone 'UTC' - and created_at < (date :end + time '00:00:00') at time zone 'America/Toronto' at time zone 'UTC'""" + and created_at < (date :end + time '00:00:00') at time zone 'America/New_York' at time zone 'UTC'""" result = db.session.execute(sql, {'start': process_date, 'end': process_date + timedelta(days=1)}) db.session.commit() diff --git a/app/dao/date_util.py b/app/dao/date_util.py index 7a2054cf44..1b7733fd62 100644 --- a/app/dao/date_util.py +++ b/app/dao/date_util.py @@ -42,7 +42,7 @@ def get_april_fools(year): :return: the datetime of April 1 for the given year, for example 2016 = 2016-03-31 23:00:00 """ return ( - pytz.timezone(os.getenv('TIMEZONE', 'America/Toronto')) + pytz.timezone(os.getenv('TIMEZONE', 'America/New_York')) .localize(datetime(year, 4, 1, 0, 0, 0)) .astimezone(pytz.UTC) .replace(tzinfo=None) diff --git a/app/utils.py b/app/utils.py index 090cf6ec83..ef63ae0aa8 100644 --- a/app/utils.py +++ b/app/utils.py @@ -10,7 +10,7 @@ from app.constants import EMAIL_TYPE, LETTER_TYPE, PRECOMPILED_LETTER, PUSH_TYPE, SMS_TYPE, UPLOAD_DOCUMENT -local_timezone = pytz.timezone(os.getenv('TIMEZONE', 'America/Toronto')) +local_timezone = pytz.timezone(os.getenv('TIMEZONE', 'America/New_York')) def pagination_links( @@ -95,12 +95,12 @@ def get_local_timezone_month_from_utc_column(column): the month in BST (British Summer Time). The database stores all timestamps as UTC without the timezone. - First set the timezone on created_at to UTC - - then convert the timezone to BST (or America/Toronto) + - then convert the timezone to BST (or America/New_York) - lastly truncate the datetime to month with which we can group queries """ return func.date_trunc( - 'month', func.timezone(os.getenv('TIMEZONE', 'America/Toronto'), func.timezone('UTC', column)) + 'month', func.timezone(os.getenv('TIMEZONE', 'America/New_York'), func.timezone('UTC', column)) ) diff --git a/migrations/versions/0183_alter_primary_key.py b/migrations/versions/0183_alter_primary_key.py index 628adfb9ef..a22ceb6677 100644 --- a/migrations/versions/0183_alter_primary_key.py +++ b/migrations/versions/0183_alter_primary_key.py @@ -43,8 +43,8 @@ def upgrade(): to_char(datum, 'iyyy/IW') AS year_calendar_week, (SELECT CASE WHEN (extract(month from datum) <= 3) THEN (extract(year FROM datum) -1) ELSE (extract(year FROM datum)) end), - (datum + TIME '00:00:00') at Time zone 'America/Toronto' at TIME zone 'utc' as utc_daytime_start, -- convert bst time to utc time - (datum + TIME '24:00:00') at Time zone 'America/Toronto' at TIME zone 'utc' as utc_daytime_end + (datum + TIME '00:00:00') at Time zone 'America/New_York' at TIME zone 'utc' as utc_daytime_start, -- convert bst time to utc time + (datum + TIME '24:00:00') at Time zone 'America/New_York' at TIME zone 'utc' as utc_daytime_end FROM ( -- There are 10 leap years in this range, so calculate 365 * 50 + 5 records SELECT '2015-01-01'::date + SEQUENCE.DAY AS datum