A social pastebin built on atproto.
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

convert times UTC->local on frontend

+16 -1
+5 -1
main.py
··· 30 30 session, 31 31 url_for, 32 32 ) 33 + from markupsafe import Markup 33 34 from pygments import highlight 34 35 from pygments.formatters import HtmlFormatter 35 36 from pygments.lexers import TextLexer, guess_lexer ··· 309 310 310 311 @app.template_filter("humandate") 311 312 def humandate_filter(value: str) -> str: 313 + """Return a <time> element that JS will convert to the viewer's local timezone.""" 312 314 try: 313 315 dt = datetime.fromisoformat(value) 314 - return dt.strftime("%b %-d, %Y at %-I:%M %p").lower() 316 + iso = dt.isoformat() 317 + fallback = dt.strftime("%b %-d, %Y at %-I:%M %p").lower() 318 + return Markup(f'<time datetime="{iso}" class="js-localtime">{fallback}</time>') 315 319 except Exception: 316 320 return value 317 321
+11
templates/base.html
··· 116 116 {% endif %} 117 117 118 118 <script> 119 + // Convert UTC timestamps to local timezone 120 + document.querySelectorAll('.js-localtime').forEach(function(el) { 121 + var dt = new Date(el.getAttribute('datetime')); 122 + if (!isNaN(dt)) { 123 + var h = dt.getHours(); 124 + var ampm = h >= 12 ? 'pm' : 'am'; 125 + h = h % 12 || 12; 126 + var months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']; 127 + el.textContent = months[dt.getMonth()] + ' ' + dt.getDate() + ', ' + dt.getFullYear() + ' at ' + h + ':' + String(dt.getMinutes()).padStart(2,'0') + ' ' + ampm; 128 + } 129 + }); 119 130 // Profile links inside card links 120 131 document.addEventListener('click', function(e) { 121 132 var link = e.target.closest('.js-profile-link');