Skip to content

Instantly share code, notes, and snippets.

@nikz
Created June 29, 2011 05:05
Show Gist options
  • Select an option

  • Save nikz/1053183 to your computer and use it in GitHub Desktop.

Select an option

Save nikz/1053183 to your computer and use it in GitHub Desktop.
Date.prototype.startOfWeek = function() {
var dayOfMonth = this.getDate() - this.getDay();
var month = (dayOfMonth > 0) ? this.getMonth() : this.getMonth() - 1;
var year = (month > 0) ? this.getFullYear() : this.getFullYear() - 1;
if (dayOfMonth < 0) {
dayOfMonth = this.getDaysInMonth(month) - (dayOfMonth * -1)
}
return new Date(year, month, dayOfMonth, this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment