Skip to content

Instantly share code, notes, and snippets.

@dmitriy-kiriyenko
Created September 30, 2011 11:39
Show Gist options
  • Save dmitriy-kiriyenko/1253511 to your computer and use it in GitHub Desktop.
Save dmitriy-kiriyenko/1253511 to your computer and use it in GitHub Desktop.
Some useful date functions for Javascript
Date.today = function() {
return (new Date()).beginningOfDay();
}
Date.prototype.beginningOfDay = function() {
var result = new Date(this);
result.setHours(0);
result.setMinutes(0);
result.setSeconds(0);
result.setMilliseconds(0);
return result;
}
Date.prototype.isPast = function() {
return this.beginningOfDay().getTime() < Date.today().getTime();
}
Date.prototype.isToday = function() {
return this.beginningOfDay().getTime() == Date.today().getTime();
}
Date.prototype.isFuture = function() {
return this.beginningOfDay().getTime() > Date.today().getTime();
}
Date.prototype.isWeekend = function(weekends) {
weekends = weekends || [0, 6];
return $.inArray(this.getDay(), weekends) >= 0
}
Date.prototype.isWeekday = function(weekends) {
return !this.isWeekend(weekends);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment