Javascript Utility Functions

function pad (str, max) {
	str = str.toString();
	return str.length < max ? pad("0" + str, max) : str;
}

function parse_time(time){
	var sep = '-';
	var pattern = /([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})\s(\d{1,2}):(\d{1,2}).*/i;
	var result = time.match(pattern);
	//console.log(result);

	if(result != null){
		var year = result[1];
		var month = pad(result[2], 2);
		var day = pad(result[3], 2);
		var hour = pad(result[4], 2);
		var min = pad(result[5], 2);

		return {
			date: year + sep + month + sep + day, 
			year: year, 
			month: month, 
			day: day, 
			hour: hour, 
			min: min
		}
	}

	return result;
}