src/constraint/weekofmonth.js
function(d, val) {
    val = val > later.wm.extent(d)[1] ? 1 : val;

    var month = later.date.nextRollover(d, val, later.wm, later.M),
        wmMax = later.wm.extent(month)[1];

    val = val > wmMax ? 1 : val || wmMax;

    // jump to the Sunday of the desired week, set to 1st of month for week 1
    return later.date.next(
        later.Y.val(month),
        later.M.val(month),
        Math.max(1, (val-1) * 7 - (later.dw.val(month)-2)));
  }
function(d, val) {
    val = val > later.wm.extent(d)[1] ? 1 : val;

    var month = later.date.nextRollover(d, val, later.wm, later.M),
        wmMax = later.wm.extent(month)[1];

    val = val > wmMax ? 1 : val || wmMax;

    // jump to the Sunday of the desired week, set to 1st of month for week 1
    return later.date.next(
        later.Y.val(month),
        later.M.val(month),
        Math.max(1, (val-1) * 7 - (later.dw.val(month)-2)));
  }
function ( d , val ) { val = val > later . wm . extent ( d ) [ 1 ] ? 1 : val ; var month = later . date . nextRollover ( d , val , later . wm , later . M ) , wmMax = later . wm . extent ( month ) [ 1 ] ; val = val > wmMax ? 1 : val || wmMax ; // jump to the Sunday of the desired week, set to 1st of month for week 1 return later . date . next ( later . Y . val ( month ) , later . M . val ( month ) , Math . max ( 1 , ( val - 1 ) * 7 - ( later . dw . val ( month ) - 2 ) ) ) ; }
Returns the start of the next instance of the week value indicated. Returns
the first day of the next month if val is greater than the number of
days in the following month.

@param {Date} d: The starting date
@param {int} val: The desired value, must be within extent
Returns the start of the next instance of the week value indicated . Returns the first day of the next month if val is greater than the number of days in the following month .