Skip to content

Commit

Permalink
#1350 Use America/New_York time zone by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbfled committed Dec 23, 2024
1 parent 9a2a4b4 commit 20b70c6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
"""
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion app/dao/date_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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))
)


Expand Down
4 changes: 2 additions & 2 deletions migrations/versions/0183_alter_primary_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20b70c6

Please sign in to comment.