Skip to content

Instantly share code, notes, and snippets.

@RodrigoEspinosa
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RodrigoEspinosa/527e9f6d60767654015b to your computer and use it in GitHub Desktop.
Save RodrigoEspinosa/527e9f6d60767654015b to your computer and use it in GitHub Desktop.
Get this: week, month and year range Date prototype
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)];
};
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