mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 07:18:26 -04:00
Fixed timezone conversion
This commit is contained in:
@@ -191,9 +191,9 @@ def convert_report_date_to_preferred_timezone(db_date_str_in_utc):
|
|||||||
utc_date_obj = utc_date_obj.astimezone(pytz.utc)
|
utc_date_obj = utc_date_obj.astimezone(pytz.utc)
|
||||||
preferred_timezone = pytz.timezone(get_user_preferred_timezone())
|
preferred_timezone = pytz.timezone(get_user_preferred_timezone())
|
||||||
preferred_date_obj = utc_date_obj.astimezone(preferred_timezone)
|
preferred_date_obj = utc_date_obj.astimezone(preferred_timezone)
|
||||||
preferred_tz_created_at = preferred_date_obj.strftime("%Y-%m-%d %I:%M:%S %p")
|
preferred_tz_created_at = preferred_date_obj.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
return f"{preferred_tz_created_at} {get_user_preferred_timezone()}"
|
return preferred_tz_created_at
|
||||||
|
|
||||||
|
|
||||||
def get_user_preferred_timezone():
|
def get_user_preferred_timezone():
|
||||||
|
|||||||
@@ -90,14 +90,14 @@ def get_notifications_csv_mock(
|
|||||||
None,
|
None,
|
||||||
[
|
[
|
||||||
"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time,Carrier\n",
|
"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time,Carrier\n",
|
||||||
"8005555555,foo,,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern,AT&T Mobility\r\n",
|
"8005555555,foo,,,Did not like it,Delivered,1943-04-19 08:00:00,AT&T Mobility\r\n",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"Anne Example",
|
"Anne Example",
|
||||||
[
|
[
|
||||||
"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time,Carrier\n",
|
"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time,Carrier\n",
|
||||||
"8005555555,foo,Anne Example,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern,AT&T Mobility\r\n", # noqa
|
"8005555555,foo,Anne Example,,Did not like it,Delivered,1943-04-19 08:00:00,AT&T Mobility\r\n", # noqa
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -145,7 +145,7 @@ def test_generate_notifications_csv_without_job(
|
|||||||
"bar.csv",
|
"bar.csv",
|
||||||
"Did not like it",
|
"Did not like it",
|
||||||
"Delivered",
|
"Delivered",
|
||||||
"1943-04-19 08:00:00 AM US/Eastern",
|
"1943-04-19 08:00:00",
|
||||||
"AT&T Mobility",
|
"AT&T Mobility",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -174,7 +174,7 @@ def test_generate_notifications_csv_without_job(
|
|||||||
"bar.csv",
|
"bar.csv",
|
||||||
"Did not like it",
|
"Did not like it",
|
||||||
"Delivered",
|
"Delivered",
|
||||||
"1943-04-19 08:00:00 AM US/Eastern",
|
"1943-04-19 08:00:00",
|
||||||
"AT&T Mobility",
|
"AT&T Mobility",
|
||||||
"🐜",
|
"🐜",
|
||||||
"🐝",
|
"🐝",
|
||||||
@@ -206,7 +206,7 @@ def test_generate_notifications_csv_without_job(
|
|||||||
"bar.csv",
|
"bar.csv",
|
||||||
"Did not like it",
|
"Did not like it",
|
||||||
"Delivered",
|
"Delivered",
|
||||||
"1943-04-19 08:00:00 AM US/Eastern",
|
"1943-04-19 08:00:00",
|
||||||
"AT&T Mobility",
|
"AT&T Mobility",
|
||||||
"🐜,🐜",
|
"🐜,🐜",
|
||||||
"🐝,🐝",
|
"🐝,🐝",
|
||||||
@@ -385,4 +385,4 @@ def test_get_errors_for_csv(
|
|||||||
def test_convert_report_date_to_preferred_timezone():
|
def test_convert_report_date_to_preferred_timezone():
|
||||||
original = "2023-11-16 05:00:00"
|
original = "2023-11-16 05:00:00"
|
||||||
altered = convert_report_date_to_preferred_timezone(original)
|
altered = convert_report_date_to_preferred_timezone(original)
|
||||||
assert altered == "2023-11-16 12:00:00 AM US/Eastern"
|
assert altered == "2023-11-16 00:00:00"
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ def test_convert_s3_csv_timestamps_with_real_format():
|
|||||||
) as mock_convert:
|
) as mock_convert:
|
||||||
|
|
||||||
def mock_conversion(timestamp):
|
def mock_conversion(timestamp):
|
||||||
return f"{timestamp} US/Eastern"
|
# Just return the timestamp as-is for testing
|
||||||
|
return timestamp
|
||||||
|
|
||||||
mock_convert.side_effect = mock_conversion
|
mock_convert.side_effect = mock_conversion
|
||||||
|
|
||||||
@@ -31,8 +32,8 @@ def test_convert_s3_csv_timestamps_with_real_format():
|
|||||||
assert mock_convert.call_count == 2
|
assert mock_convert.call_count == 2
|
||||||
mock_convert.assert_any_call("2024-03-15 17:19:00")
|
mock_convert.assert_any_call("2024-03-15 17:19:00")
|
||||||
mock_convert.assert_any_call("2024-03-15 20:30:00")
|
mock_convert.assert_any_call("2024-03-15 20:30:00")
|
||||||
assert "2024-03-15 17:19:00 US/Eastern" in full_result
|
assert "2024-03-15 17:19:00" in full_result
|
||||||
assert "2024-03-15 20:30:00 US/Eastern" in full_result
|
assert "2024-03-15 20:30:00" in full_result
|
||||||
|
|
||||||
|
|
||||||
def test_convert_s3_csv_handles_empty_csv():
|
def test_convert_s3_csv_handles_empty_csv():
|
||||||
@@ -56,7 +57,7 @@ def test_convert_s3_csv_handles_bytes():
|
|||||||
with patch(
|
with patch(
|
||||||
"app.utils.s3_csv.convert_report_date_to_preferred_timezone"
|
"app.utils.s3_csv.convert_report_date_to_preferred_timezone"
|
||||||
) as mock_convert:
|
) as mock_convert:
|
||||||
mock_convert.return_value = "2024-01-15 03:30:00 PM US/Eastern"
|
mock_convert.return_value = "2024-01-15 15:30:00"
|
||||||
|
|
||||||
result = list(convert_s3_csv_timestamps(csv_bytes))
|
result = list(convert_s3_csv_timestamps(csv_bytes))
|
||||||
assert len(result) == 2
|
assert len(result) == 2
|
||||||
@@ -73,14 +74,14 @@ def test_convert_s3_csv_handles_malformed_dates():
|
|||||||
) as mock_convert:
|
) as mock_convert:
|
||||||
mock_convert.side_effect = [
|
mock_convert.side_effect = [
|
||||||
Exception("Invalid date"),
|
Exception("Invalid date"),
|
||||||
"2024-01-15 04:45:00 PM US/Eastern",
|
"2024-01-15 16:45:00",
|
||||||
]
|
]
|
||||||
|
|
||||||
result = list(convert_s3_csv_timestamps(csv_content))
|
result = list(convert_s3_csv_timestamps(csv_content))
|
||||||
full_result = "".join(result)
|
full_result = "".join(result)
|
||||||
|
|
||||||
assert "INVALID_DATE" in full_result
|
assert "INVALID_DATE" in full_result
|
||||||
assert "2024-01-15 04:45:00 PM US/Eastern" in full_result
|
assert "2024-01-15 16:45:00" in full_result
|
||||||
|
|
||||||
|
|
||||||
def test_finds_time_column_dynamically():
|
def test_finds_time_column_dynamically():
|
||||||
@@ -109,5 +110,7 @@ def test_actual_timezone_conversion():
|
|||||||
|
|
||||||
result = convert_report_date_to_preferred_timezone("2024-01-15 20:30:00")
|
result = convert_report_date_to_preferred_timezone("2024-01-15 20:30:00")
|
||||||
|
|
||||||
assert "03:30:00 PM" in result or "15:30:00 PM" in result
|
# Should be in 24-hour format without AM/PM or timezone
|
||||||
assert "US/Eastern" in result
|
assert "15:30:00" in result
|
||||||
|
assert "PM" not in result
|
||||||
|
assert "US/Eastern" not in result
|
||||||
|
|||||||
Reference in New Issue
Block a user