DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Get Annual Event Name
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;
}
});





