Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timezone to title in span element #175

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/mkdocs_git_revision_date_localized_plugin/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def get_date_formats(
loc_revision_date.strftime("%H:%M:%S"),
]
),
"datetime-timezone": " ".join(
[
format_date(loc_revision_date, format="long", locale=locale),
loc_revision_date.strftime("%H:%M:%S %Z"),
]
),
"iso_date": loc_revision_date.strftime("%Y-%m-%d"),
"iso_datetime": loc_revision_date.strftime("%Y-%m-%d %H:%M:%S"),
"timeago": '<span class="timeago" datetime="%s" locale="%s"></span>' % (loc_revision_date.isoformat(), locale),
Expand Down
2 changes: 1 addition & 1 deletion src/mkdocs_git_revision_date_localized_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def add_spans(date_formats: Dict[str, str]) -> Dict[str, str]:
"""
Wraps the date string in <span> elements with CSS identifiers.
"""
datetime_string = date_formats["datetime"]
datetime_string = date_formats["datetime-timezone"]
for date_type, date_string in date_formats.items():
date_formats[date_type] = (
'<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-%s" title="%s">%s</span>'
Expand Down
7 changes: 7 additions & 0 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_get_dates():
expected_output = {
"date": "January 1, 1970",
"datetime": "January 1, 1970 00:00:00",
"datetime-timezone": "January 1, 1970 00:00:00 UTC",
"iso_date": "1970-01-01",
"iso_datetime": "1970-01-01 00:00:00",
"timeago": '<span class="timeago" datetime="1970-01-01T00:00:00+00:00" locale="en"></span>',
Expand All @@ -26,6 +27,7 @@ def test_get_dates():
expected_output = {
"date": "1 janvier 1970",
"datetime": "1 janvier 1970 00:00:00",
"datetime-timezone": "1 janvier 1970 00:00:00 UTC",
"iso_date": "1970-01-01",
"iso_datetime": "1970-01-01 00:00:00",
"timeago": '<span class="timeago" datetime="1970-01-01T00:00:00+00:00" locale="fr"></span>',
Expand All @@ -37,6 +39,7 @@ def test_get_dates():
expected_output = {
"date": "1 de janeiro de 1970",
"datetime": "1 de janeiro de 1970 00:00:00",
"datetime-timezone": "1 de janeiro de 1970 00:00:00 UTC",
"iso_date": "1970-01-01",
"iso_datetime": "1970-01-01 00:00:00",
"timeago": '<span class="timeago" datetime="1970-01-01T00:00:00+00:00" locale="pt_BR"></span>',
Expand All @@ -52,6 +55,7 @@ def test_get_dates():
expected_output = {
"date": "January 1, 1970",
"datetime": "January 1, 1970 00:00:00",
"datetime-timezone": "January 1, 1970 00:00:00 UTC",
"iso_date": "1970-01-01",
"iso_datetime": "1970-01-01 00:00:00",
"timeago": '<span class="timeago" datetime="1970-01-01T00:00:00+00:00" locale="en"></span>',
Expand All @@ -63,6 +67,7 @@ def test_get_dates():
expected_output = {
"date": "January 1, 1970",
"datetime": "January 1, 1970 02:00:00",
"datetime-timezone": "January 1, 1970 02:00:00 CET",
"iso_date": "1970-01-01",
"iso_datetime": "1970-01-01 02:00:00",
"timeago": '<span class="timeago" datetime="1970-01-01T02:00:00+01:00" locale="en"></span>',
Expand All @@ -84,6 +89,7 @@ def test_get_dates():
expected_output = {
"date": "October 15, 2023",
"datetime": "October 15, 2023 13:32:04",
"datetime-timezone": "October 15, 2023 13:32:04 CEST",
"iso_date": "2023-10-15",
"iso_datetime": "2023-10-15 13:32:04",
"timeago": '<span class="timeago" datetime="2023-10-15T13:32:04+02:00" locale="en"></span>',
Expand All @@ -94,6 +100,7 @@ def test_get_dates():
assert get_date_formats(1582397529) == {
"date": "February 22, 2020",
"datetime": "February 22, 2020 18:52:09",
"datetime-timezone": "February 22, 2020 18:52:09 UTC",
"iso_date": "2020-02-22",
"iso_datetime": "2020-02-22 18:52:09",
"timeago": '<span class="timeago" datetime="2020-02-22T18:52:09+00:00" locale="en"></span>',
Expand Down