Last active
August 29, 2015 14:01
-
-
Save RodrigoEspinosa/527e9f6d60767654015b to your computer and use it in GitHub Desktop.
Get this: week, month and year range Date prototype
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
Date.prototype.getThisWeek = function () { | |
var y = this.getFullYear(), | |
m = this.getMonth(), | |
f = this.getDate() - this.getDay(), | |
l = f + 6; | |
return [new Date(y, m, f), new Date(y, m, l)]; | |
}; | |
Date.prototype.getThisMonth = function () { | |
var y = this.getFullYear(), | |
m = this.getMonth(); | |
return [new Date(y, m, 1), new Date(y, m + 1, 0)]; | |
}; | |
Date.prototype.getThisYear = function () { | |
var y = this.getFullYear(); | |
return [new Date(y, 0, 0), new Date(y + 1, 0, 0)]; | |
}; |
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
window.selectedTimeRange = (selTimeRange === 'this week') ? | |
new Date().getThisWeek() : (selTimeRange === 'this month') ? | |
new Date().getThisMonth() : new Date().getThisYear(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment