I am testing out some time formatting systems (like Twitter has a time since posting next to a tweet) and so I set up a barebones HTML page to run my javascript on, however the output is not being displayed in my div. Why is this happening? Any help is appreciated!
Page:
<html>
<head>
<title>Testing</title>
</head>
<body>
<div id="app">
<script>
var app = require('ago');
#('app').innerHTML = timeSince(old_date);
</script>
</div>
</body>
</html>
Script:
var old_date = new Date("November 13, 2017 5:00 PM");
function #(sel) {
return document.getElementById(sel);
}
function timeSince(post_minute) {
var seconds = Math.floor((new Date() - post_minute) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {
return interval + "y";
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
return interval + "mo.";
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
return interval + "d";
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
return interval + "h";
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
return interval + "m";
}
return Math.floor(seconds) + " seconds";
}