Skip to content

Instantly share code, notes, and snippets.

@uudashr
Created May 21, 2014 08:14
Show Gist options
  • Save uudashr/b8f0a868b75cafcdd0c6 to your computer and use it in GitHub Desktop.
Save uudashr/b8f0a868b75cafcdd0c6 to your computer and use it in GitHub Desktop.
Get the bounds of a day
function dayBounds(date) {
var t1 = new Date(date.getTime());
t1.setHours(0, 0, 0, 0);
var t2 = new Date(date.getTime());
t2.setHours(23, 59, 59, 999);
return [t1, t2];
}
Date.prototype.dayBounds = function() {
return dayBounds(this);
};
function sameDay(date1, date2) {
return date1.getFullYear() == date2.getFullYear() &&
date1.getMonth() == date2.getMonth() &&
date1.getDate() == date2.getDate();
}
Date.prototype.sameDay = function(otherDate) {
return sameDay(this, otherDate);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment