Object.extend(Date.prototype, { getAnnualEventName: function() { var annualEvents = $H({ 'newyear': '1/1-1/3', 'haloween': '10/31', 'christmas': '12/1-12/25', }); var today = new Date(this.getYear(), this.getMonth(), this.getDate()); var annualEventName = ''; annualEvents.each( function(pair, index) { days = pair[1].split('-'); if(!days[1]) { if(today.getTime() == new Date(this.getYear(), days[0].split('/')[0] - 1, days[0].split('/')[1]).getTime()) { annualEventName = pair[0]; } } else { from = new Date(this.getYear(), days[0].split('/')[0] - 1, days[0].split('/')[1]); to = new Date(this.getYear(), days[1].split('/')[0] - 1, days[1].split('/')[1]); if(from > to) { if(!(today > to && today < from)) { annualEventName = pair[0]; } } else { if(today >= from && today <= to) { annualEventName = pair[0]; } } } }.bind(this) ); return annualEventName; } });
You need to create an account or log in to post comments to this site.