Here you can find the source of subWeeks(value)
Date.prototype.subWeeks = function(value) { this.subDays(value * 7);/*w w w . j a v a 2 s . c o m*/ return this; };
Date.prototype.getRealWeek = function() var monday = this; if (monday.getDay() < 1) { monday = monday.clone().next().monday(); return monday.getWeek(); };
Date.prototype.getStudyWeek = function () { var inc = (this.getDay() == 6) ? 1 : 0; return this.getWeek() + inc; };
Date.prototype.moveToBeginOfWeek = function(weekStart) if (this.getDay() != weekStart) { this.moveToDayOfWeek(weekStart, -1); return this; };
Date.prototype.moveToEndOfWeek = function(weekStart) var weekEndDay = weekStart + 6; if (weekEndDay > 6) { weekEndDay -= 7; if (this.getDay() != weekEndDay) { this.moveToDayOfWeek(weekEndDay, 1); return this; };
Date.prototype.offsetByWeek = function(offset) { this.setTime(this.getTime() + offset * (7 * 24 * 60 * 60 * 1000)); return this; };
Date.prototype.toWeekDays = function () { var weekday = this.clone() if (!weekday.is().sunday()) { weekday.sunday().add(-7).days() var week = [weekday.clone()] for (var day = 0; day < 6; day++) { week.push(weekday.add(1).days().clone()) return week Date.prototype.toNextWeekDays = function () { return this.add(7).days().toWeekDays() Date.prototype.toPreviousWeekDays = function () { return this.add(-7).days().toWeekDays() Date.prototype.compare = function (date) { var year = this.getYear() - date.getYear() if (year > 0) return "In " + year + " Years" else if (year < 0) return -year + " Years Ago" else { var month = this.getMonth() - date.getMonth() if (month > 0) return "In " + month + " Months" else if (month < 0) return -month + " Months Ago" else { var week = this.getWeekOfYear() - date.getWeekOfYear() if (week > 0) return "In " + week + " Weeks" else if (week < 0) return -week + " Weeks Ago" else { if (this.getDay() - date.getDay() == 0) return "Today" else return this.toString("dddd")
Date.prototype.toWeekEnd = function (startsFromSunday) { var dayOfWeek = this.getDay(); if (startsFromSunday) { return this.addDays(6 - dayOfWeek); if (dayOfWeek == 0) { dayOfWeek = 7; return this.addDays(7 - dayOfWeek); ...
Date.prototype.toWeekStart = function (startsFromSunday) { var dayOfWeek = this.getDay(); if (startsFromSunday) { return this.addDays(-dayOfWeek); if (dayOfWeek == 0) { dayOfWeek = 7; return this.addDays(1 - dayOfWeek); ...
var firstMonday = new Date(1970, 0, 5).getTime() Date.prototype.weekNo = function() { var _date = new Date(this) _date.setHours(0,0,0,0) _date.setDate(_date.getDate() - (_date.getDay() || 7)) var weekNo = Math.ceil((((_date - firstMonday) / 86400000) + 1) / 7) return weekNo Date.prototype.weekNoRelative = function() { ...