mirror of
https://github.com/chylex/Lightning-Tracker.git
synced 2024-12-22 14:42:46 +01:00
25 lines
881 B
JavaScript
25 lines
881 B
JavaScript
document.addEventListener("DOMContentLoaded", function(){
|
|
const months = ["Jan", "Feb", "Mar",
|
|
"Apr", "May", "Jun",
|
|
"Jul", "Aug", "Sep",
|
|
"Oct", "Nov", "Dec"];
|
|
|
|
function pad(n){
|
|
return n.toString().padStart(2, "0");
|
|
}
|
|
|
|
for(/** @type HTMLElement */ const time of document.getElementsByTagName("time")){
|
|
const type = time.getAttribute("data-kind");
|
|
const date = new Date(Date.parse(time.getAttribute("datetime")));
|
|
|
|
const datePart = pad(date.getDate()) + " " + months[date.getMonth()] + " " + date.getFullYear();
|
|
|
|
if (type === "date"){
|
|
time.innerText = datePart;
|
|
}
|
|
else if (type === "datetime"){
|
|
time.innerText = datePart + ", " + pad(date.getHours()) + ":" + pad(date.getMinutes());
|
|
}
|
|
}
|
|
});
|