Skip to content

Commit

Permalink
Merge pull request Pikaday#42 from rikkert/issue41
Browse files Browse the repository at this point in the history
Add function to set the time elements of a date to the start of a day.
  • Loading branch information
rikkert committed Mar 15, 2013
2 parents 6663911 + 4702a70 commit a3d3061
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pikaday.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@
return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
},

setToStartOfDay = function(date)
{
if (isDate(date)) date.setHours(0,0,0,0);
},

compareDates = function(a,b)
{
// weak date comparison (use date.setHours(0,0,0,0) to ensure correct result)
// weak date comparison (use setToStartOfDay(date) to ensure correct result)
return a.getTime() === b.getTime();
},

Expand Down Expand Up @@ -501,11 +506,13 @@
opts.maxDate = opts.minDate = false;
}
if (opts.minDate) {
opts.minYear = opts.minDate.getFullYear();
setToStartOfDay(opts.minDate);
opts.minYear = opts.minDate.getFullYear();
opts.minMonth = opts.minDate.getMonth();
}
if (opts.maxDate) {
opts.maxYear = opts.maxDate.getFullYear();
setToStartOfDay(opts.maxDate);
opts.maxYear = opts.maxDate.getFullYear();
opts.maxMonth = opts.maxDate.getMonth();
}

Expand Down Expand Up @@ -583,7 +590,7 @@
}

this._d = new Date(date.getTime());
this._d.setHours(0,0,0,0);
setToStartOfDay(this._d);
this.gotoDate(this._d);

if (this._o.field) {
Expand Down Expand Up @@ -715,7 +722,7 @@
before = new Date(year, month, 1).getDay(),
data = [],
row = [];
now.setHours(0,0,0,0);
setToStartOfDay(now);
if (opts.firstDay > 0) {
before -= opts.firstDay;
if (before < 0) {
Expand Down

0 comments on commit a3d3061

Please sign in to comment.