# HG changeset patch # User neko259 # Date 2015-03-09 10:01:09 # Node ID 67ce9645e56aa82a2a6b76fc2f97c1125eb7f60f # Parent e788a57bbd3a182c790f10f0c39b3709e72128b5 Set timestamps to local ones by JS diff --git a/boards/static/js/main.js b/boards/static/js/main.js --- a/boards/static/js/main.js +++ b/boards/static/js/main.js @@ -40,6 +40,34 @@ function highlightCode(node) { }); } +/** + * Translate timestamps to local ones + */ +function translate_time() { + var els = $('time'); + if (!els.length) { + return; + } + + var locale = window.navigator.language; + var formatter = new Intl.DateTimeFormat( + locale, + { + weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', + hour: 'numeric', minute: '2-digit', second: '2-digit' + } + ); + + els.each(function() { + var el = $(this); + var dateAttr = el.attr('datetime'); + if (dateAttr) { + var date = new Date(dateAttr); + el.text(formatter.format(date)); + } + }); +} + $( document ).ready(function() { hideEmailFromForm(); @@ -53,4 +81,6 @@ function highlightCode(node) { addRefLinkPreview(); highlightCode($(document)); + + translate_time(); }); diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -106,6 +106,8 @@ function getThreadDiff() { // TODO Process removed posts if any $('.metapanel').attr('data-last-update', data.last_update); + + translate_time(); }) } @@ -140,7 +142,7 @@ function updatePost(postHtml) { showNewPostsTitle(1); lastUpdate = post.children('.post-info').first() - .children('.pub_time').first().text(); + .children('.pub_time').first().html(); if (bottom) { scrollToBottom(); @@ -195,7 +197,7 @@ function updateMetadataPanel(lastUpdate) if (lastUpdate !== '') { var lastUpdateField = $('#last-update'); - lastUpdateField.text(lastUpdate); + lastUpdateField.html(lastUpdate); blink(lastUpdateField); } diff --git a/boards/templates/boards/post.html b/boards/templates/boards/post.html --- a/boards/templates/boards/post.html +++ b/boards/templates/boards/post.html @@ -18,7 +18,7 @@ onclick="javascript:addQuickReply('{{ post.id }}'); return false;" title="{% trans 'Quote' %}" {% endif %}>({{ post.get_absolute_id }}) {{ post.title }} - {{ post.pub_time|date:'r' }} + {% comment %} Thread death time needs to be shown only if the thread is alredy archived and this is an opening post (thread death time) or a post for popup diff --git a/boards/templates/boards/thread.html b/boards/templates/boards/thread.html --- a/boards/templates/boards/thread.html +++ b/boards/templates/boards/thread.html @@ -85,7 +85,7 @@ {{ thread.get_reply_count }}/{{ max_replies }} {% trans 'messages' %}, {{ thread.get_images_count }} {% trans 'images' %}. - {% trans 'Last update: ' %}{{ thread.last_edit_time|date:'r' }} + {% trans 'Last update: ' %} [RSS] {% endcache %} diff --git a/boards/templates/boards/thread_gallery.html b/boards/templates/boards/thread_gallery.html --- a/boards/templates/boards/thread_gallery.html +++ b/boards/templates/boards/thread_gallery.html @@ -58,7 +58,7 @@ {{ thread.get_reply_count }}/{{ max_replies }} {% trans 'messages' %}, {{ thread.get_images_count }} {% trans 'images' %}. - {% trans 'Last update: ' %}{{ thread.last_edit_time|date:'r' }} + {% trans 'Last update: ' %} [RSS] {% endcache %}