Created
May 18, 2014 11:55
-
-
Save uudashr/863f7d6f7f63ba446476 to your computer and use it in GitHub Desktop.
Get week bounds from a date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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