Return the week number, relative to its month

@param  int|Date d Date or timestamp in milliseconds
@return int Week number, relative to the month [0-5]
763759
function (d) {
		"use strict";

		if (typeof d === "number") {
			d = new Date(d);
		}

		var monthFirstWeekNumber = this.getWeekNumber(new Date(d.getFullYear(), d.getMonth()));
		return this.getWeekNumber(d) - monthFirstWeekNumber - 1;
	}
1373418
public static Integer getDayOfWeek(Date date) {

        if (date == null)
            return null;

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        return calendar.get(Calendar.DAY_OF_WEEK);
    }
211796
public static Date getDateOfWeeksBack(final int weeksBack, final Date date) {

    return dateBack(Calendar.WEEK_OF_MONTH, weeksBack, date);
  }
1126487
public static Date getLastDayFromCurrentWeek(Date d) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);        
        // depends on Locale (if a week starts on Monday or on Sunday)
        if (cal.getFirstDayOfWeek() == Calendar.SUNDAY) {
        	cal.add(Calendar.WEEK_OF_YEAR, 1);  
        }	
        cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999);
        return cal.getTime();
    }
735818
static function num2week($num, $two = true)
    {
        if ($num == '6')
        {
            $num = '日';
        }
        else
        {
            $num = Tool::num2han($num + 1);
        }
        if ($two)
        {
            return self::WEEK_TWO . $num;
        }
        else
        {
            return self::WEEK_THREE . $num;
        }
    }
953728
public static Date toDateDayOfWeek(int dayOfWeek)
   {
	Calendar cal = Calendar.getInstance();
	cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
	
	return cal.getTime();
   }
47592
public Weekday getDayOfWeek() {

        long utcDays = this.gregorian.getDaysSinceEpochUTC();
        return Weekday.valueOf(MathUtils.floorModulo(utcDays + 5, 7) + 1);

    }
414537
public static Date floor(Date d) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }
934348
public static Date getWeekDay(Date dt, int weekDay) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(dt);
        if (weekDay == 7) {
            weekDay = 1;
        } else {
            weekDay++;
        }
        cal.set(GregorianCalendar.DAY_OF_WEEK, weekDay);
        return cal.getTime();
    }
352777
public static Date getLastNDay(Date d, int n, int unitType) {
    	Calendar cal = Calendar.getInstance();
        cal.setTime(d); 
        cal.add(unitType, -n);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
1057652
public static int dayOfWeek(){
		setTime();
		int dayofweek = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (dayofweek == 0) {
			dayofweek = 7;
		}
		return dayofweek;
	}
806500
function monthCalendar(date) {
    var start = date.clone().startOf("month").startOf("week").startOf("day");
    var end = date.clone().endOf("month").endOf("week").startOf("day");
    var result = [];
    var current = start.weekday(0).subtract(1, "d");
    while (true) {
        current = current.clone().add(1, "d");
        result.push(current);
        if (areDatesEqual(current, end)) {
            break;
        }
    }
    return result;
}
1074706
static Date toDate(double d) {
        GregorianCalendar ret = new GregorianCalendar(1899,11,30);
        int days = (int)d;
        d -= days;
        ret.add(Calendar.DATE,days);
        d *= 24;
        int hours = (int)d;
        ret.add(Calendar.HOUR,hours);
        d -= hours;
        d *= 60;
//        d += 0.5; // round
        int min = (int)d;
        ret.add(Calendar.MINUTE,min);

        d -= min;
        d *= 60;
        int secs = (int) d;
        ret.add(Calendar.SECOND, secs);

        return ret.getTime();
    }
865229
public int getWeek()
  {
    int dow4th = (int) ((_dayOfEpoch - _dayOfYear + 3) % 7 + 10) % 7;
    int ww1monday = 3 - dow4th;

    if (_dayOfYear < ww1monday)
      return 53;

    int week = (_dayOfYear - ww1monday) / 7 + 1;

    if (_dayOfYear >= 360) {
      int days = 365 + (_isLeapYear ? 1 : 0);
      long nextNewYear = (_dayOfEpoch - _dayOfYear + days);

      int dowNext4th = (int) ((nextNewYear + 3) % 7 + 10) % 7;
      int nextWw1Monday = 3 - dowNext4th;

      if (days <= _dayOfYear - nextWw1Monday)
        return 1;
    }

    return week;
  }
1043521
public static Date getLastDayFromCurrentYear(Date d) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);                
        cal.set(Calendar.MONTH, Calendar.DECEMBER);
        cal.set(Calendar.DAY_OF_MONTH, 31);
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999);
        return cal.getTime();
    }
668630
public static int getMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.MONTH);
    }
206869
public static Date plusWeeks(Date date, int weeks) {
		return plus(date, weeks, DateTimeField.WEEKS);
	}