// localTime.js

/*
 * the names of the days of the week
 */
var IP2C_DAY_NAME = new Array(
	"Sunday",
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday"
);

/*
 * the names of the months of the year
 */
var IP2C_MONTH_NAME = new Array(
	"January",
	"February",
	"March",
	"April",
	"May",
	"June",
	"July",
	"August",
	"September",
	"October",
	"November",
	"December"
);

/*
 * format a time in epoch seconds in the following format:
 *     Wed, Oct 31 2007 20:37:06 
 */
function ip2c_formatEpoch(epoch)
{
	var localTime = new Date();
	localTime.setTime(epoch * 1000);
	var day = IP2C_DAY_NAME[localTime.getDay()].substr(0, 3);
	var date = localTime.getDate();
	var month = IP2C_MONTH_NAME[localTime.getMonth()].substr(0, 3);
	var year = localTime.getFullYear();
	var hours = ip2c_formatHMS(localTime.getHours());
	var minutes = ip2c_formatHMS(localTime.getMinutes());
	var seconds = ip2c_formatHMS(localTime.getSeconds());
	var s = day + ", " + month + " " + date + " " +
		year + " " + hours + ":" + minutes + ":" + seconds;
	return s;
}

/*
 * preceed hours, minutes and seconds with a zero if less than 10
 */
function ip2c_formatHMS(hms)
{
	return (hms < 10 ? "0" : "") + hms;
}
