francescomecca.eu/output/assets/js/fancydates.js

21 lines
489 B
JavaScript
Raw Normal View History

2018-11-10 18:19:00 +01:00
function fancydates(fanciness, date_format) {
if (fanciness == 0) {
return;
}
2019-03-06 10:42:59 +01:00
var dates = document.querySelectorAll('.dt-published, .dt-updated, .listdate');
2018-11-10 18:19:00 +01:00
var l = dates.length;
for (var i = 0; i < l; i++) {
var d = moment(dates[i].attributes.datetime.value);
var o;
if (fanciness == 1) {
o = d.local().format(date_format);
} else {
o = d.fromNow();
}
dates[i].innerHTML = o;
}
}