Skip to content

Instantly share code, notes, and snippets.

@uudashr
Created May 18, 2014 11:55
Show Gist options
  • Save uudashr/863f7d6f7f63ba446476 to your computer and use it in GitHub Desktop.
Save uudashr/863f7d6f7f63ba446476 to your computer and use it in GitHub Desktop.
Get week bounds from a date
/*
* Usage:
* new Date().weekBounds()
*
* or
*
* weekBounds(new Date());
*/
function weekBounds(date) {
var ONE_DAY = 1000 * 60 * 60 * 24;
var d1 = new Date(date.getTime() - (date.getDay() * ONE_DAY));
d1.setHours(0, 0, 0, 0);
var d2 = new Date(date.getTime() + (6 - date.getDay()) * ONE_DAY);
d2.setHours(23, 59, 59, 999);
return [d1, d2];
}
Date.prototype.weekBounds = function() {
return weekBounds(this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment