1
0
mirror of https://github.com/writeas/writefreely synced 2024-12-12 08:36:14 +01:00
writefreely/static/js/localdate.js
Rob Loranger caca8f0ae2
show timestamps in local date/locale
this adds a helper script to rewrite all time elements with a proper
datetime attribute into the users locale via the browser
navigator.language.

collection, collection-post and chorus-collection-post templates now
include this script
2019-10-03 09:47:08 -07:00

10 lines
316 B
JavaScript

function toLocalDate(el) {
var d = new Date(el.getAttribute("datetime"));
el.textContent = d.toLocaleDateString(navigator.language || "en-US", { year: 'numeric', month: 'long', day: 'numeric' });
}
var $dates = document.querySelectorAll("time");
for (var i=0; i < $dates.length; i++) {
toLocalDate($dates[i]);
}