function Now(){return new Date();};var JANUARY=0;var FEBRUARY=1;var MARCH=2;var APRIL=3;var MAY=4;var JUNE=5;var JULY=6;var AUGUST=7;var SEPTEMBER=8;var OCTOBER=9;var NOVEMBER=10;var DECEMBER=11;var SUNDAY=0;var MONDAY=1;var TUESDAY=2;var WEDNESDAY=3;var THURSDAY=4;var FRIDAY=5;var SATURDAY=6;var SECONDS_CF=1000;var MINUTES_CF=60000;var HOURS_CF=3600000;var DAYS_CF=86400000;var WEEKS_CF=604800000;var FORTNIGHTS_CF=1209600000;var MONTHS_CF=2592000000;var QUARTERS_CF=7776000000;var YEARS_CF=31557600000;var DECADES_CF=315576000000;var CENTURIES_CF=3155760000000;Date.prototype.addMilliseconds=function(ms){return new Date(new Date().setTime(this.getTime()+(ms)));};Date.prototype.addSeconds=function(s){return this.addMilliseconds(s*SECONDS_CF);};Date.prototype.addMinutes=function(m){return this.addMilliseconds(m*MINUTES_CF);};Date.prototype.addHours=function(h){return this.addMilliseconds(h*HOURS_CF);};Date.prototype.addDays=function(d){return this.addMilliseconds(d*DAYS_CF);};Date.prototype.addWeeks=function(w){return this.addMilliseconds(w*WEEKS_CF);};Date.prototype.addFortnights=function(w){return this.addMilliseconds(w*FORTNIGHTS_CF);};Date.prototype.addMonths=function(mm){return this.addMilliseconds(mm*MONTHS_CF);};Date.prototype.addYears=function(yy){return this.addMilliseconds(yy*YEARS_CF);};Date.prototype.subtractMilliseconds=function(ms){return new Date(new Date().setTime(this.getTime()-(ms)));};Date.prototype.subtractSeconds=function(s){return this.subtractMilliseconds(s*SECONDS_CF);};Date.prototype.subtractMinutes=function(m){return this.subtractMilliseconds(m*MINUTES_CF);};Date.prototype.subtractHours=function(h){return this.subtractMilliseconds(h*HOURS_CF);};Date.prototype.subtractDays=function(d){return this.subtractMilliseconds(d*DAYS_CF);};Date.prototype.subtractWeeks=function(w){return this.subtractMilliseconds(w*WEEKS_CF);};Date.prototype.subtractFortnights=function(w){return this.subtractMilliseconds(w*FORTNIGHTS_CF);};Date.prototype.subtractMonths=function(mm){return this.subtractMilliseconds(mm*MONTHS_CF);};Date.prototype.subtractYears=function(yy){return this.subtractMilliseconds(yy*YEARS_CF);};Date.prototype._addMilliseconds=function(ms){this.setTime(this.getTime()+(ms));return this;};Date.prototype._addSeconds=function(s){return this._addMilliseconds(s*SECONDS_CF);};Date.prototype._addMinutes=function(m){return this._addMilliseconds(m*MINUTES_CF);};Date.prototype._addHours=function(h){return this._addMilliseconds(h*HOURS_CF);};Date.prototype._addDays=function(d){return this._addMilliseconds(d*DAYS_CF);};Date.prototype._addWeeks=function(w){return this._addMilliseconds(w*WEEKS_CF);};Date.prototype._addFortnights=function(w){return this._addMilliseconds(w*FORTNIGHTS_CF);};Date.prototype._addMonths=function(mm){return this._addMilliseconds(mm*MONTHS_CF);};Date.prototype._addYears=function(yy){return this._addMilliseconds(yy*YEARS_CF);};Date.prototype._subtractMilliseconds=function(ms){this.setTime(this.getTime()-(ms));return this;};Date.prototype._subtractSeconds=function(s){return this._subtractMilliseconds(s*SECONDS_CF);};Date.prototype._subtractMinutes=function(m){return this._subtractMilliseconds(m*MINUTES_CF);};Date.prototype._subtractHours=function(h){return this._subtractMilliseconds(h*HOURS_CF);};Date.prototype._subtractDays=function(d){return this._subtractMilliseconds(d*DAYS_CF);};Date.prototype._subtractWeeks=function(w){return this._subtractMilliseconds(w*WEEKS_CF);};Date.prototype._subtractFortnights=function(w){return this._subtractMilliseconds(w*FORTNIGHTS_CF);};Date.prototype._subtractMonths=function(mm){return this._subtractMilliseconds(mm*MONTHS_CF);};Date.prototype._subtractYears=function(yy){return this._subtractMilliseconds(yy*YEARS_CF);};Date.prototype.getMonthName=function(){var index=(0==arguments.length)?this.getMonth():arguments[0];switch(index){case JANUARY:return "January";case FEBRUARY:return "February";case MARCH:return "March";case APRIL:return "April";case MAY:return "May";case JUNE:return "June";case JULY:return "July";case AUGUST:return "August";case SEPTEMBER:return "September";case OCTOBER:return "October";case NOVEMBER:return "November";case DECEMBER:return "December";default:throw "Invalid month index: "+index.toString();}};Date.prototype.getMonthAbbreviation=function(){var index=(0==arguments.length)?this.getMonth():arguments[0];switch(index){case JANUARY:return "Jan";case FEBRUARY:return "Feb";case MARCH:return "Mar";case APRIL:return "Apr";case MAY:return "May";case JUNE:return "Jun";case JULY:return "Jul";case AUGUST:return "Aug";case SEPTEMBER:return "Sep";case OCTOBER:return "Oct";case NOVEMBER:return "Nov";case DECEMBER:return "Dec";default:throw "Invalid month index: "+index.toString();}};Date.prototype.getDayName=function(){var index=(0==arguments.length)?this.getDay():arguments[0];switch(index){case SUNDAY:return "Sunday";case MONDAY:return "Monday";case TUESDAY:return "Tuesday";case WEDNESDAY:return "Wednesday";case THURSDAY:return "Thursday";case FRIDAY:return "Friday";case SATURDAY:return "Saturday";default:throw "Invalid day index: "+index.toString();}};Date.prototype.getDayAbbreviation=function(){var index=(0==arguments.length)?this.getDay():arguments[0];switch(index){case SUNDAY:return "Sun";case MONDAY:return "Mon";case TUESDAY:return "Tue";case WEDNESDAY:return "Wed";case THURSDAY:return "Thu";case FRIDAY:return "Fri";case SATURDAY:return "Sat";default:throw "Invalid day index: "+index.toString();}};Date.prototype.getCivilianHours=function(){return(this.getHours()<12)?this.getHours():this.getHours()-12;};Date.prototype.getMeridiem=function(){return(this.getHours()<12)?"AM":"PM";};Date.prototype.to_s=Date.prototype.toString;Date.prototype.format=function(fs){fs=fs.replace(/%YYYY/,this.getFullYear().toString());fs=fs.replace(/%YY/,this.getFullYear().toString().substr(2,2));fs=fs.replace(/%MMMM/,this.getMonthName(this.getMonth()).toString());fs=fs.replace(/%MMM/,this.getMonthAbbreviation(this.getMonth()).toString());fs=fs.replace(/%MM/,(this.getMonth()+1)>9?(this.getMonth()+1).toString():"0"+(this.getMonth()+1).toString());fs=fs.replace(/%M/,(this.getMonth()+1).toString());fs=fs.replace(/%DDDD/,this.getDayName(this.getDay()).toString());fs=fs.replace(/%DDD/,this.getDayAbbreviation(this.getDay()).toString());fs=fs.replace(/%DD/,this.getDate()>9?this.getDate().toString():"0"+this.getDate().toString());fs=fs.replace(/%D/,this.getDate().toString());fs=fs.replace(/%HH/,this.getHours()>9?this.getHours().toString():"0"+this.getHours().toString());fs=fs.replace(/%H/,this.getHours().toString());fs=fs.replace(/%hh/,this.getCivilianHours()>9?this.getCivilianHours().toString():"0"+this.getCivilianHours().toString());fs=fs.replace(/%h/,this.getCivilianHours());fs=fs.replace(/%mm/,this.getMinutes()>9?this.getMinutes().toString():"0"+this.getMinutes().toString());fs=fs.replace(/%m/,this.getMinutes().toString());fs=fs.replace(/%ss/,this.getSeconds()>9?this.getSeconds().toString():"0"+this.getSeconds().toString());fs=fs.replace(/%s/,this.getSeconds().toString());fs=fs.replace(/%nnn/,this.getMilliseconds().toString());fs=fs.replace(/%p/,this.getMeridiem());return fs;};Date.prototype.getDaysInMonth=function(){switch(this.getMonth()){case JANUARY:return 31;case FEBRUARY:return this.isLeapYear()?29:28;case MARCH:return 31;case APRIL:return 30;case MAY:return 31;case JUNE:return 30;case JULY:return 31;case AUGUST:return 31;case SEPTEMBER:return 30;case OCTOBER:return 31;case NOVEMBER:return 30;case DECEMBER:return 31;}};Date.prototype.toString=function(){if(0==arguments.length||1<arguments.length)return this.to_s();return this.format(arguments[0].toString());};Date.prototype.isLeapYear=function(){if(0==this.getFullYear()%400)return true;if(0==this.getFullYear()%100)return false;return(0==this.getFullYear()%4)?true:false;};Date.prototype.zeroTime=function(){var dt=this.clone();dt.setHours(0);dt.setMinutes(0);dt.setSeconds(0);dt.setMilliseconds(0);return dt;};Date.prototype.noon=function(){var dt=this.clone();dt.setHours(12);dt.setMinutes(0);dt.setSeconds(0);dt.setMilliseconds(0);return dt;};Date.prototype.firstDayOfMonth=function(){return new Date(this.getFullYear(),this.getMonth(),1,12,0,0);};Date.prototype.lastDayOfMonth=function(){return new Date(this.getFullYear(),this.getMonth(),this.getDaysInMonth(),12,0,0);};Date.prototype.clone=function(){var dt=new Date();dt.setTime(this.getTime());return dt;};Date.yesterday=function(){return new Date().noon().subtractDays(1);};Date.today=function(){return new Date().noon();};Date.tomorrow=function(){return new Date().noon().addDays(1);};Date.lastWeek=function(){return new Date().noon().subtractWeeks(1);};Date.nextWeek=function(){return new Date().noon().addWeeks(1);};Date.lastMonth=function(){return new Date().noon().subtractMonths(1);};Date.nextFortnight=function(){return new Date().noon().addFortnights(1);};Date.lastFortnight=function(){return new Date().noon().subtractFortnights(1);};Date.nextMonth=function(){return new Date().noon().addMonths(1);};Date.lastYear=function(){return new Date().noon().subtractYears(1);};Date.nextYear=function(){return new Date().noon().addYears(1);};Number.prototype.millisecondsFromNow=function(){return new Date().addMilliseconds(this);};Number.prototype.millisecondFromNow=function(){return this.millisecondsFromNow();};Number.prototype.secondsFromNow=function(){return new Date().addSeconds(this);};Number.prototype.secondFromNow=function(){return this.secondsFromNow();};Number.prototype.minutesFromNow=function(){return new Date().addMinutes(this);};Number.prototype.minuteFromNow=function(){return this.minutesFromNow();};Number.prototype.daysFromNow=function(){return new Date().addDays(this);};Number.prototype.dayFromNow=function(){return this.daysFromNow();};Number.prototype.weeksFromNow=function(){return new Date().addWeeks(this);};Number.prototype.weekFromNow=function(){return this.weeksFromNow();};Number.prototype.fortnightsFromNow=function(){return new Date().addFortnights(this);};Number.prototype.fortnightFromNow=function(){return this.fortnightsFromNow();};Number.prototype.monthsFromNow=function(){return new Date().addMonths(this);};Number.prototype.monthFromNow=function(){return this.monthsFromNow();};Number.prototype.yearsFromNow=function(){return new Date().addYears(this);};Number.prototype.yearFromNow=function(){return this.yearsFromNow();};Number.prototype.millisecondsAgo=function(){return new Date().subtractMilliSeconds(this);};Number.prototype.millisecondAgo=function(){return this.millisecondsAgo();};Number.prototype.secondsAgo=function(){return new Date().subtractSeconds(this);};Number.prototype.secondAgo=function(){return this.secondsAgo();};Number.prototype.minutesAgo=function(){return new Date().subtractMinutes(this);};Number.prototype.minuteAgo=function(){return this.minutesAgo();};Number.prototype.hoursAgo=function(){return new Date().subtractHours(this);};Number.prototype.hourAgo=function(){return this.hoursAgo();};Number.prototype.daysAgo=function(){return new Date().subtractDays(this);};Number.prototype.dayAgo=function(){return this.daysAgo();};Number.prototype.weeksAgo=function(){return new Date().subtractWeeks(this);};Number.prototype.weekAgo=function(){return this.weeksAgo();};Number.prototype.fortnightsAgo=function(){return new Date().subtractFortnights(this);};Number.prototype.fortnightAgo=function(){return this.fortnightsAgo();};Number.prototype.monthsAgo=function(){return new Date().subtractMonths(this);};Number.prototype.monthAgo=function(){return this.monthsAgo();};Number.prototype.yearsAgo=function(){return new Date().subtractYears(this);};Number.prototype.yearAgo=function(){return this.yearsAgo();};function TimeSpan(ms){this.milliseconds=Math.abs(ms);this.seconds=Math.round(this.milliseconds/SECONDS_CF);this.minutes=Math.round(this.milliseconds/MINUTES_CF);this.hours=Math.round(this.milliseconds/HOURS_CF);this.days=Math.round(this.milliseconds/DAYS_CF);this.weeks=Math.round(this.milliseconds/WEEKS_CF);this.fortnights=Math.round(this.milliseconds/FORTNIGHTS_CF);this.months=Math.round(this.milliseconds/MONTHS_CF);this.quarters=Math.round(this.milliseconds/QUARTERS_CF);this.years=Math.round(this.milliseconds/YEARS_CF);this.decades=Math.round(this.milliseconds/DECADES_CF);this.centuries=Math.round(this.milliseconds/CENTURIES_CF);};TimeSpan.prototype.toString=function(){return this.milliseconds.toString();};


