mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 03:38:26 -04:00
use dates rather than datetimes when comparing with bst_date
bst_date is a date field. Comparing dates with datetimes in postgres gets confusing and dangerous. See this example, where a date evaluates as older than midnight that same day. ``` notification_api=# select '2019-04-01' >= '2019-04-01 00:00'; ?column? ---------- f (1 row) ``` By only using dates everywhere, we reduce the chance of these bugs happening
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, date, time
|
||||
|
||||
from notifications_utils.timezones import convert_bst_to_utc
|
||||
import pytz
|
||||
@@ -64,6 +64,9 @@ def get_current_financial_year_start_year():
|
||||
|
||||
|
||||
def get_financial_year_for_datetime(start_date):
|
||||
if type(start_date) == date:
|
||||
start_date = datetime.combine(start_date, time.min)
|
||||
|
||||
year = int(start_date.strftime('%Y'))
|
||||
if start_date < get_april_fools(year):
|
||||
return year - 1
|
||||
|
||||
Reference in New Issue
Block a user