module('apps.AtomFeed').requires().toRun(function() {

Object.subclass('AtomDate');

Object.extend(AtomDate, {
	pattern: /^(\d{4})(?:-(\d{2}))?(?:-(\d{2}))?(?:[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d*))?)?([Zz])?(?:([+-])(\d{2}):(\d{2}))?$/,

	localoffset: (new Date()).getTimezoneOffset(),

	padding: function(val,char,count) {
		var value = "";
		while(count > 0) {
			if (val < Math.pow(10,count)) value = char + value;
			count--;
		}
		return value + val;
	},

	parse: function(val) {
		if (!val) throw "Invalid Date";
		if (val instanceof Date) return val;
		var m = AtomDate.pattern.exec(val);
		var year = new Number(m[1]?m[1]:0);
		var month = new Number(m[2]?m[2]-1:0);
		var day = new Number(m[3]?m[3]:0);
		var hour = new Number(m[4]?m[4]:0);
		var minute = new Number(m[5]?m[5]:0);
		var second = new Number(m[6]?m[6]:0);
		var millis = new Number(m[7]?m[7]:0);
		var gmt = m[8];
		var dir = m[9];
		var offhour = new Number(m[10]?m[10]:0);
		var offmin = new Number(m[11]?m[11]:0);

		if (dir && offhour && offmin) {
			var offset = ((offhour * 60) + offmin);
				if (dir == "+") {
					minute -= offset;
				} else if (dir == "-") {
					minute += offset;
				}
			}
		return new Date(Date.UTC(year,month,day,hour,minute,second,millis));
	},
});

}) // end of module