Using the below time system, how would I set the current hour to a specific hour without changing any other fields (days, years, months, etc.)?
/* A method to change a date using intervals */
if (! setup.changeDate) {
setup.changeDate = function(date, interval, units) {
var d = new Date(date); // Don't change original date.
switch(interval.toLowerCase()) {
case 'years':
d.setFullYear(d.getFullYear() + units);
break;
case 'quarters':
d.setMonth(d.getMonth() + 3 * units);
break;
case 'months':
d.setMonth(d.getMonth() + units);
break;
case 'weeks':
d.setDate(d.getDate() + 7 * units);
break;
case 'days':
d.setDate(d.getDate() + units);
break;
case 'hours':
d.setTime(d.getTime() + units * 3600000);
break;
case 'minutes':
d.setTime(d.getTime() + units * 60000);
break;
case 'seconds':
d.setTime(d.getTime() + units * 1000);
break;
default:
break;
}
return d;
};
}
/* A method to change a date using intervals */
if (! setup.changeDate) {
setup.changeDate = function(date, interval, units) {
var d = new Date(date); // Don't change original date.
switch(interval.toLowerCase()) {
case 'years':
d.setFullYear(d.getFullYear() + units);
break;
case 'quarters':
d.setMonth(d.getMonth() + 3 * units);
break;
case 'months':
d.setMonth(d.getMonth() + units);
break;
case 'weeks':
d.setDate(d.getDate() + 7 * units);
break;
case 'days':
d.setDate(d.getDate() + units);
break;
case 'hours':
d.setTime(d.getTime() + units * 3600000);
break;
case 'minutes':
d.setTime(d.getTime() + units * 60000);
break;
case 'seconds':
d.setTime(d.getTime() + units * 1000);
break;
default:
break;
}
return d;
};
}