src/constraint/dayofweekcount.js
function(d, val) {
    val = val > later.dc.extent(d)[1] ? 1 : val;
    var month = later.date.nextRollover(d, val, later.dc, later.M),
        dcMax = later.dc.extent(month)[1];

    val = val > dcMax ? 1 : val;

    var next = later.date.next(
      later.Y.val(month),
      later.M.val(month),
      val === 0 ? later.D.extent(month)[1] - 6 : 1 + (7 * (val - 1))
    );

    if(next.getTime() <= d.getTime()) {
      month = later.M.next(d, later.M.val(d)+1);

      return later.date.next(
        later.Y.val(month),
        later.M.val(month),
        val === 0 ? later.D.extent(month)[1] - 6 : 1 + (7 * (val - 1))
      );
    }

    return next;
  }
function(d, val) {
    val = val > later.dc.extent(d)[1] ? 1 : val;
    var month = later.date.nextRollover(d, val, later.dc, later.M),
        dcMax = later.dc.extent(month)[1];

    val = val > dcMax ? 1 : val;

    var next = later.date.next(
      later.Y.val(month),
      later.M.val(month),
      val === 0 ? later.D.extent(month)[1] - 6 : 1 + (7 * (val - 1))
    );

    if(next.getTime() <= d.getTime()) {
      month = later.M.next(d, later.M.val(d)+1);

      return later.date.next(
        later.Y.val(month),
        later.M.val(month),
        val === 0 ? later.D.extent(month)[1] - 6 : 1 + (7 * (val - 1))
      );
    }

    return next;
  }
function ( d , val ) { val = val > later . dc . extent ( d ) [ 1 ] ? 1 : val ; var month = later . date . nextRollover ( d , val , later . dc , later . M ) , dcMax = later . dc . extent ( month ) [ 1 ] ; val = val > dcMax ? 1 : val ; var next = later . date . next ( later . Y . val ( month ) , later . M . val ( month ) , val === 0 ? later . D . extent ( month ) [ 1 ] - 6 : 1 + ( 7 * ( val - 1 ) ) ) ; if ( next . getTime ( ) <= d . getTime ( ) ) { month = later . M . next ( d , later . M . val ( d ) + 1 ) ; return later . date . next ( later . Y . val ( month ) , later . M . val ( month ) , val === 0 ? later . D . extent ( month ) [ 1 ] - 6 : 1 + ( 7 * ( val - 1 ) ) ) ; } return next ; }
Returns the next earliest date with the day of week count specified.

@param {Date} d: The starting date
@param {int} val: The desired value, must be within extent
Returns the next earliest date with the day of week count specified .