Skip to content

Commit 773b913

Browse files
authored
Merge pull request #1145 from alphagov/2130-short-month
2130: Format date-times on detailed case notes page with short month names
2 parents 9e7a705 + 2a0e630 commit 773b913

5 files changed

Lines changed: 83 additions & 4 deletions

File tree

accessibility_monitoring_platform/apps/common/templatetags/common_tags.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
from ..utils import ( # pylint: disable=relative-beyond-top-level
1616
amp_format_date,
17-
amp_format_trunc_date,
17+
amp_format_date_short_month,
1818
amp_format_datetime,
19+
amp_format_datetime_short_month,
1920
undo_double_escapes,
2021
)
2122

@@ -51,7 +52,7 @@ def amp_date(date_to_format: date) -> str:
5152
@register.filter
5253
def amp_date_trunc(date_to_format: date) -> str:
5354
"""Format truncated date according to GDS style guide"""
54-
return amp_format_trunc_date(date_to_format)
55+
return amp_format_date_short_month(date_to_format)
5556

5657

5758
@register.filter
@@ -61,3 +62,14 @@ def amp_datetime(datetime_to_format: datetime) -> str:
6162
return amp_format_datetime(timezone.localtime(datetime_to_format))
6263
else:
6364
return ""
65+
66+
67+
@register.filter
68+
def amp_datetime_short_month(datetime_to_format: datetime) -> str:
69+
"""
70+
Format date and time according to GDS style guide with short month name (e.g. Jan)
71+
"""
72+
if datetime_to_format:
73+
return amp_format_datetime_short_month(timezone.localtime(datetime_to_format))
74+
else:
75+
return ""

accessibility_monitoring_platform/apps/common/tests/test_templatetags.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
"""
22
Test templatetags of common app
33
"""
4+
45
from datetime import date, datetime, timezone
56

67
import pytest
78

89
from ..templatetags.common_tags import (
910
amp_date,
11+
amp_date_trunc,
1012
amp_datetime,
13+
amp_datetime_short_month,
1114
list_item_by_index,
1215
markdown_to_html,
1316
)
@@ -59,6 +62,18 @@ def test_amp_date(date_to_format, expected_result):
5962
assert amp_date(date_to_format) == expected_result
6063

6164

65+
@pytest.mark.parametrize(
66+
"date_to_format,expected_result",
67+
[
68+
(date(2021, 4, 1), "1 Apr 2021"),
69+
(None, ""),
70+
],
71+
)
72+
def test_amp_date_trunc(date_to_format, expected_result):
73+
"""Test date formatted according to GDS style guide."""
74+
assert amp_date_trunc(date_to_format) == expected_result
75+
76+
6277
@pytest.mark.parametrize(
6378
"datetime_to_format,expected_result",
6479
[
@@ -70,3 +85,16 @@ def test_amp_date(date_to_format, expected_result):
7085
def test_amp_datetime(datetime_to_format, expected_result):
7186
"""Test date and time formatted according to GDS style guide."""
7287
assert amp_datetime(datetime_to_format) == expected_result
88+
89+
90+
@pytest.mark.parametrize(
91+
"datetime_to_format,expected_result",
92+
[
93+
(datetime(2021, 1, 4, 9, 1, 0, 0, timezone.utc), "4 Jan 2021 9:01am"),
94+
(datetime(2021, 7, 4, 8, 1, 0, 0, timezone.utc), "4 Jul 2021 9:01am"),
95+
(None, ""),
96+
],
97+
)
98+
def test_amp_datetime_short_month(datetime_to_format, expected_result):
99+
"""Test date and time formatted according to GDS style guide."""
100+
assert amp_datetime_short_month(datetime_to_format) == expected_result

accessibility_monitoring_platform/apps/common/tests/test_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
from ..utils import (
2626
SessionExpiry,
2727
amp_format_date,
28+
amp_format_date_short_month,
2829
amp_format_datetime,
30+
amp_format_datetime_short_month,
2931
amp_format_time,
3032
build_filters,
3133
calculate_percentage,
@@ -354,6 +356,18 @@ def test_amp_format_date(date_to_format, expected_result):
354356
assert amp_format_date(date_to_format) == expected_result
355357

356358

359+
@pytest.mark.parametrize(
360+
"date_to_format,expected_result",
361+
[
362+
(date(2021, 4, 1), "1 Apr 2021"),
363+
(None, ""),
364+
],
365+
)
366+
def test_amp_format_date_trunc(date_to_format, expected_result):
367+
"""Test date formatted according to GDS style guide with a short month name"""
368+
assert amp_format_date_short_month(date_to_format) == expected_result
369+
370+
357371
@pytest.mark.parametrize(
358372
"datetime_to_format,expected_result",
359373
[
@@ -378,6 +392,20 @@ def test_amp_format_datetime(datetime_to_format, expected_result):
378392
assert amp_format_datetime(datetime_to_format) == expected_result
379393

380394

395+
@pytest.mark.parametrize(
396+
"datetime_to_format,expected_result",
397+
[
398+
(datetime(2021, 4, 1, 9, 1), "1 Apr 2021 9:01am"),
399+
(None, ""),
400+
],
401+
)
402+
def test_amp_format_datetime_short_month(datetime_to_format, expected_result):
403+
"""
404+
Test date and time formatted according to GDS style guide with a short month.
405+
"""
406+
assert amp_format_datetime_short_month(datetime_to_format) == expected_result
407+
408+
381409
def test_undo_double_escapes():
382410
"""
383411
Test Undo double escapes, where & has been replaced with & in escaped html

accessibility_monitoring_platform/apps/common/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def amp_format_date(date_to_format: date) -> str:
173173
return f"{date_to_format:%-d %B %Y}" if date_to_format else ""
174174

175175

176-
def amp_format_trunc_date(date_to_format: date) -> str:
176+
def amp_format_date_short_month(date_to_format: date) -> str:
177177
"""Format date according to GDS style guide"""
178178
return f"{date_to_format:%-d %b %Y}" if date_to_format else ""
179179

@@ -192,6 +192,17 @@ def amp_format_datetime(datetime_to_format: datetime) -> str:
192192
)
193193

194194

195+
def amp_format_datetime_short_month(datetime_to_format: datetime) -> str:
196+
"""
197+
Format date and time according to GDS style guide with short month name (e.g. Jan)
198+
"""
199+
return (
200+
f"{amp_format_date_short_month(datetime_to_format)} {amp_format_time(datetime_to_format)}"
201+
if datetime_to_format
202+
else ""
203+
)
204+
205+
195206
def undo_double_escapes(html: str) -> str:
196207
"""Undo double escapes, where & has been replaced with & in escaped html"""
197208
return (

accessibility_monitoring_platform/apps/detailed/templates/detailed/forms/note_create.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</b>
5454
</p>
5555
<p class="govuk-body amp-margin-bottom-5">{{ detailed_case_event.created_by.get_full_name }}</p>
56-
<p class="govuk-body amp-margin-bottom-5">{{ detailed_case_event.created|amp_datetime }}</p>
56+
<p class="govuk-body amp-margin-bottom-5">{{ detailed_case_event.created|amp_datetime_short_month }}</p>
5757
{% if detailed_case_event.event_type == 'note' %}
5858
<p class="govuk-body amp-margin-bottom-5">
5959
<a href="{% url 'detailed:edit-case-note' detailed_case_event.id %}"

0 commit comments

Comments
 (0)