patx/gitman
Use readable localized dates and link the copyright footer on every page
Commit 0783ca5 · patx · Nov 4 at 9:17PM
Comments
No comments yet.
Diff
diff --git a/app.py b/app.py
index 82ff24f..23277f8 100644
--- a/app.py
+++ b/app.py
@@ -1166,7 +1166,11 @@ def format_timestamp(value, timezone='UTC'):
moment = dt.datetime.fromisoformat(str(value).replace('Z', '+00:00'))
if moment.tzinfo is None:
moment = moment.replace(tzinfo=dt.timezone.utc)
- return moment.astimezone(ZoneInfo(timezone)).isoformat(timespec='seconds').replace('+00:00', 'Z')
+ zone = ZoneInfo(timezone)
+ local = moment.astimezone(zone)
+ date = f"{local.strftime('%b')} {local.day}" if local.year == dt.datetime.now(zone).year else local.strftime('%m/%d/%Y')
+ clock = local.strftime('%I:%M%p').lstrip('0')
+ return f'{date} at {clock}'
except (ValueError, ZoneInfoNotFoundError):
return str(value)
diff --git a/static/styles.css b/static/styles.css
index a9fc53b..060ea73 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -659,6 +659,7 @@ th { color: var(--ink); font-weight: 700; }
/* The public welcome page shares the site's theme and logo. */
.landing-page main.page { display: grid; place-items: center; max-width: none; padding: 2rem 1.5rem; }
+.landing-page .colophon { justify-content: center; text-align: center; padding-block: 1rem; }
.welcome-hero { display: flex; flex-direction: column; align-items: center; gap: 1.75rem; width: 100%; max-width: 44rem; text-align: center; }
.welcome-logo { display: flex; align-items: center; justify-content: center; gap: clamp(1rem, 3vw, 2rem); margin: 0; line-height: 1; }
.welcome-logo svg { flex: 0 0 auto; height: auto; }
diff --git a/templates/base.tpl b/templates/base.tpl
index 1b61cf2..9347e4b 100644
--- a/templates/base.tpl
+++ b/templates/base.tpl
@@ -20,7 +20,7 @@
% if not get('landing', False) and theme != 'light':
<link rel="stylesheet" href="/static/vendor/highlight.js/github-dark.min.css"{{!' media="(prefers-color-scheme: dark)"' if theme == 'auto' else ''}}>
% end
- <link rel="stylesheet" href="/static/styles.css?v=24">
+ <link rel="stylesheet" href="/static/styles.css?v=25">
</head>
<body class="{{'landing-page' if get('landing', False) else ''}}">
% if not get("landing", False):
@@ -86,11 +86,11 @@
% end
{{!base}}
</main>
- % if not get("landing", False):
% import time
<footer class="colophon">
- <p>© {{time.strftime("%Y")}} GitMan</p>
+ <p>© {{time.strftime("%Y")}} <a href="https://gitman.io/patx/gitman">GitMan</a></p>
</footer>
+ % if not get("landing", False):
<script src="/static/mentions.js?v=2" defer></script>
% if user:
<script src="/static/contributor-picker.js?v=2" defer></script>
diff --git a/tests/test_app.py b/tests/test_app.py
index 3f7dfcb..484a777 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -558,7 +558,8 @@ def test_homepage_redirect_and_header_repo_search_finds_repositories_by_fuzzy_na
assert anonymous_index_response.status_code == 200
assert 'data-repo-search-url="/-/repos/search"' not in anonymous_index_response.text
assert '<header class="site-header">' not in anonymous_index_response.text
- assert '<footer' not in anonymous_index_response.text
+ assert '<footer class="colophon">' in anonymous_index_response.text
+ assert 'href="https://gitman.io/patx/gitman"' in anonymous_index_response.text
assert 'class="welcome-hero"' in anonymous_index_response.text
assert 'href="/login"' in anonymous_index_response.text
assert 'href="/signup"' in anonymous_index_response.text
@@ -2854,7 +2855,32 @@ def test_git_upload_spooling_stops_at_bound_without_declared_length():
gitman.spool_request_body(BytesIO(b'x' * 1025), max_bytes=1024)
-def test_site_settings_persist_timezone_and_localize_dates(isolated_app):
+def freeze_timestamp_clock(monkeypatch, value):
+ original = gitman.dt.datetime
+ frozen = original.fromisoformat(value)
+ class FixedDateTime(original):
+ @classmethod
+ def now(cls, tz=None):
+ return frozen.astimezone(tz) if tz else frozen.replace(tzinfo=None)
+ monkeypatch.setattr(gitman.dt, 'datetime', FixedDateTime)
+
+
[email protected]('now,value,zone,expected', [
+ ('2026-11-04T12:00:00+00:00', '2026-10-10T13:45:00Z', 'UTC', 'Oct 10 at 1:45PM'),
+ ('2026-11-04T12:00:00+00:00', '2025-12-31T01:45:00Z', 'UTC', '12/31/2025 at 1:45AM'),
+ ('2026-11-04T12:00:00+00:00', '2026-01-01T00:00:00Z', 'UTC', 'Jan 1 at 12:00AM'),
+ ('2026-11-04T12:00:00+00:00', '2026-01-01T12:00:00Z', 'UTC', 'Jan 1 at 12:00PM'),
+ ('2026-01-01T00:30:00+00:00', '2025-12-31T23:45:00Z', 'America/New_York', 'Dec 31 at 6:45PM'),
+ ('2026-01-01T00:30:00+00:00', '2025-12-31T23:45:00Z', 'UTC', '12/31/2025 at 11:45PM'),
+ ('2026-11-04T12:00:00+00:00', '2026-10-10T13:45:00Z', 'Asia/Kolkata', 'Oct 10 at 7:15PM'),
+])
+def test_format_timestamp_uses_readable_dates_and_viewers_local_year(monkeypatch, now, value, zone, expected):
+ freeze_timestamp_clock(monkeypatch, now)
+ assert gitman.format_timestamp(value, zone) == expected
+
+
+def test_site_settings_persist_timezone_and_localize_dates(isolated_app, monkeypatch):
+ freeze_timestamp_clock(monkeypatch, '2026-11-04T12:00:00+00:00')
owner = create_user('alice')
isolated_app.create_repository(owner, 'demo', '')
repo = isolated_app.get_repo('alice', 'demo')
@@ -2867,12 +2893,12 @@ def test_site_settings_persist_timezone_and_localize_dates(isolated_app):
assert saved.status_code == 200
assert 'Site settings updated.' in saved.text
assert saved.text.index('id="profile-settings-title"') < saved.text.index('id="site-settings-title"') < saved.text.index('id="password-settings-title"')
- assert '2026-01-07T21:29:44-05:00' in client.get('/alice').text
- assert '2026-05-07T22:29:44-04:00' in client.get('/alice/demo/issues').text
- assert '2026-05-08T02:29:44Z' in WsgiClient(isolated_app.app).get('/alice/demo/issues').text
+ assert 'Jan 7 at 9:29PM' in client.get('/alice').text
+ assert 'May 7 at 10:29PM' in client.get('/alice/demo/issues').text
+ assert 'May 8 at 2:29AM' in WsgiClient(isolated_app.app).get('/alice/demo/issues').text
second = WsgiClient(isolated_app.app)
login_client(second, 'alice')
- assert '2026-05-07T22:29:44-04:00' in second.get('/alice/demo/issues').text
+ assert 'May 7 at 10:29PM' in second.get('/alice/demo/issues').text
assert isolated_app.get_user_by_id(owner['id'])['timezone_preference'] == 'America/New_York'
invalid = client.post('/settings/site', {'theme_preference': 'light', 'timezone_preference': 'Invalid/Zone'})
assert invalid.status_code == 400
@@ -2881,7 +2907,7 @@ def test_site_settings_persist_timezone_and_localize_dates(isolated_app):
client.post('/settings', {'bio': 'Profile update'})
assert isolated_app.get_user_by_id(owner['id'])['timezone_preference'] == 'America/New_York'
client.post('/settings/site', {'theme_preference': 'auto', 'timezone_preference': 'Asia/Kolkata'})
- assert '2026-05-08T07:59:44+05:30' in client.get('/alice/demo/issues').text
+ assert 'May 8 at 7:59AM' in client.get('/alice/demo/issues').text
def test_current_password_check_requires_csrf_and_throttles_without_changing_credentials(isolated_app, monkeypatch):