/*
 * Copyright 2008-2009 Palm, Inc. All rights reserved.
 */

/**
 * Returns the time at midnight for this date.
 * 
 * @return A new data object with the same date, but time at midnight.
 */
Date.prototype.getMidnight = function() {
	var delta = this.getHours()*60*60*1000 + this.getMinutes()*60*1000 + 
				this.getSeconds()*1000 + this.getMilliseconds();
	
	return new Date(this.getTime() - delta);
};

/**
 * Add the specified number of minutes to this this object and return
 * the result in a new data object.
 *  
 * @param {Nujmber} minutes The number of minutes to add.
 * @return {Date} The new date object.
 */
Date.prototype.addMinutes = function(minutes) {
    return new Date(this.getTime() + minutes*60*1000);
};

/**
 * Add the specified number of days to this this object and return
 * the result in a new data object.
 *  
 * @param {Nujmber} days The number of days to add.
 * @return {Date} The new date object.
 */
Date.prototype.addDays = function(days) {
    return new Date(this.getTime() + days*24*60*60*1000);
};

/**
 * Return a new date object in UTC. 
 * 
 * @return {Date} The new date object in equivalent UTC time.
 */
Date.prototype.getUTC = function(days) {
	return this.addMinutes( this.getTimezoneOffset() );
};

/**
 * Set the time of this data object to an epoch value in UTC.
 * 
 * @param {Number} utc The epoch in UTC (milliseconds).
 */
Date.prototype.setUTCTime = function(utc) {
	this.setTime(utc - this.getTimezoneOffset() * 60 * 1000);
};
