initial timezone pass, which breaks many tests

This commit is contained in:
stvnrlly
2022-11-22 12:00:29 -05:00
parent 3a3239a27e
commit 46723b6c11
11 changed files with 117 additions and 107 deletions

View File

@@ -9,6 +9,7 @@ from numbers import Number
import ago
import dateutil
import humanize
import pytz
from flask import Markup, url_for
from notifications_utils.field import Field
from notifications_utils.formatters import make_quotes_smart
@@ -18,7 +19,7 @@ from notifications_utils.recipients import (
validate_phone_number,
)
from notifications_utils.take import Take
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
from notifications_utils.timezones import convert_utc_to_local_timezone
def convert_to_boolean(value):
@@ -74,17 +75,18 @@ def format_datetime_numeric(date):
def format_date_numeric(date):
return utc_string_to_aware_gmt_datetime(date).strftime('%Y-%m-%d')
return convert_utc_to_local_timezone(date).strftime('%Y-%m-%d')
def format_time_24h(date):
return utc_string_to_aware_gmt_datetime(date).strftime('%H:%M')
return convert_utc_to_local_timezone(date).strftime('%H:%M')
def get_human_day(time, date_prefix=''):
# Add 1 minute to transform 00:00 into midnight today instead of midnight tomorrow
date = (utc_string_to_aware_gmt_datetime(time) - timedelta(minutes=1)).date()
time = dateutil.parser.parse(time, ignoretz=True)
date = (convert_utc_to_local_timezone(time) - timedelta(minutes=1)).date()
now = datetime.utcnow()
if date == (now + timedelta(days=1)).date():
@@ -106,25 +108,26 @@ def get_human_day(time, date_prefix=''):
def format_time(date):
date = dateutil.parser.parse(date, ignoretz=True)
return {
'12:00AM': 'Midnight',
'12:00PM': 'Midday'
'12:00PM': 'Noon'
}.get(
utc_string_to_aware_gmt_datetime(date).strftime('%-I:%M%p'),
utc_string_to_aware_gmt_datetime(date).strftime('%-I:%M%p')
convert_utc_to_local_timezone(date).strftime('%-I:%M%p'),
convert_utc_to_local_timezone(date).strftime('%-I:%M%p')
).lower()
def format_date(date):
return utc_string_to_aware_gmt_datetime(date).strftime('%A %d %B %Y')
return convert_utc_to_local_timezone(date).strftime('%A %d %B %Y')
def format_date_normal(date):
return utc_string_to_aware_gmt_datetime(date).strftime('%d %B %Y').lstrip('0')
return convert_utc_to_local_timezone(date).strftime('%d %B %Y').lstrip('0')
def format_date_short(date):
return _format_datetime_short(utc_string_to_aware_gmt_datetime(date))
return _format_datetime_short(convert_utc_to_local_timezone(date))
def format_date_human(date):
@@ -139,7 +142,7 @@ def format_datetime_human(date, date_prefix=''):
def format_day_of_week(date):
return utc_string_to_aware_gmt_datetime(date).strftime('%A')
return convert_utc_to_local_timezone(date).strftime('%A')
def _format_datetime_short(datetime):
@@ -155,10 +158,11 @@ def naturaltime_without_indefinite_article(date):
def format_delta(date):
date = dateutil.parser.parse(date, ignoretz=True)
delta = (
datetime.now(timezone.utc)
) - (
utc_string_to_aware_gmt_datetime(date)
convert_utc_to_local_timezone(date).replace(tzinfo=pytz.utc)
)
if delta < timedelta(seconds=30):
return "just now"
@@ -168,8 +172,9 @@ def format_delta(date):
def format_delta_days(date):
date = dateutil.parser.parse(date, ignoretz=True)
now = datetime.now(timezone.utc)
date = utc_string_to_aware_gmt_datetime(date)
date = convert_utc_to_local_timezone(date).replace(tzinfo=pytz.utc)
if date.strftime('%Y-%m-%d') == now.strftime('%Y-%m-%d'):
return "today"
if date.strftime('%Y-%m-%d') == (now - timedelta(days=1)).strftime('%Y-%m-%d'):