Skip to content

Instantly share code, notes, and snippets.

@jskorpan
Created February 23, 2012 21:35
Show Gist options
  • Select an option

  • Save jskorpan/1895189 to your computer and use it in GitHub Desktop.

Select an option

Save jskorpan/1895189 to your computer and use it in GitHub Desktop.
Time wasted this day and this year in percent
<html>
<head>
<title>How much of this year and this day have you wasted in percent down to 10 painful decimals</title>
</head>
<body>
<div style="height:auto;">
<div align="center" id="headingyear" style="font-size:25px"></div>
<div align="center" id="timeleftyear" style="font-family:Monospace;font-size:30px"></div>
<br>
<div align="center" id="headingday" style="font-size:20px"></div>
<div align="center" id="timeleftday" style="font-family:Monospace;font-size:30px"></div>
<br>
<div style="position:absolute;bottom:0;left:0;">
<i>Terribly coded by <a href="https://gist.github.com/1895189">jskorpan</a></i>
</div>
</div>
</body>
<script language="javascript">
var endDateYear;
var startDateYear;
function update()
{
var now = new Date();
if (now.getDate() != startDateDay.getDate())
{
init();
return;
}
if (now.getFullYear() != startDateDay.getFullYear())
{
init();
return;
}
var delta = endDateYear - startDateYear;
var elapsed = now - startDateYear;
var spent = (elapsed / delta) * 100;
document.getElementById("timeleftyear").innerHTML = spent.toFixed(10) + "%";
delta = endDateDay - startDateDay;
elapsed = now - startDateDay;
spent = (elapsed / delta) * 100;
document.getElementById("timeleftday").innerHTML = spent.toFixed(10) + "%";
}
function init()
{
endDateYear = new Date(new Date().getFullYear() + 1, 0, 1, 0, 0, 0);
startDateYear = new Date(new Date().getFullYear(), 0, 1, 0, 0, 0);
var now = new Date();
startDateDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
endDateDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 0, 0, 0, 0);
document.getElementById("headingyear").innerHTML = "How much of " + (new Date().getFullYear()) + " have you wasted?";
document.getElementById("headingday").innerHTML = "How much of this day have you wasted?";
}
init();
window.setInterval("update()", 30);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment