News for hackers. Stuff that matters.
Re:Pickadate.js by Stratoscope on Wednesday November 21, 2012 @03:12PM (#4816093)
Ha! I was thinking about my version of getCountDays() and realized there was probably a bug in it. Did anyone else see it?

  getCountDays( 2012, 2 )  // Daylight time began March 11
  30  // oops
new Date(year,month,...) uses local time, so the day will be an hour longer or shorter when the time changes.

A quick and dirty fix would be to use Math.round instead of Math.floor:

    getCountDays = function( year, month ) {
        var msInMonth = new Date(year,month+1) - new Date(year,month);
        return Math.round( msInMonth / MILLISECONDS_IN_DAY );
    },
And maybe better to use UTC? (I'd stick with Math.round at the same time.)

    getCountDays = function( year, month ) {
        var msInMonth = Date.UTC(year,month+1) - Date.UTC(year,month);
        return Math.round( msInMonth / MILLISECONDS_IN_DAY );
    },

There are no comments on this comment yet.