I went to the web timer page today (or, looked at it, I keep it open on one of my screens) to fill in the day of year and realized that I had used the wrong method. I admit, I read the documentation wrong. I verified the android app at this point and confirmed that it’s showing the correct date. The web page was a simple fix, but since I didn’t want to do the math (I have other things to do to, ya know), I looked up what existing solutions were already out there.

The cleanest and most elegant one I found was at http://javascript.about.com/library/bldayyear.htm. They basically wrote an extension to the javascript date library, included here:

Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this – onejan) / 86400000);
}

So, while dates were off by about 30 for one day, all things are well again in the world!

Facebooktwittergoogle_plusredditpinterestlinkedinmail