I’m really new to Meteor and Javascript, so I might be doing this in the most convoluted way but any help or advice would be greatly appreciated!
I have all these variables that are repeated between helpers in the same template. Is there a way to condense this?
Template.eventinfo.helpers({
'displayDate': function(){
var datestart = this.datestart;
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var today = (curr_year + "-" + curr_month + "-" + curr_date);
var todayday = today.slice(8)
var startday = datestart.slice(8);
if (datestart >= today){
return startday;
} else {
return todayday;
}
},
'displayMonth': function(){
var datestart = this.datestart;
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var today = (curr_year + "-" + curr_month + "-" + curr_date);
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var startmostr = datestart.slice(5,7);
var thismonth = monthNames[d.getMonth()];
var startmonth = monthNames[startmostr-1];
if (datestart >= today){
return startmonth;
} else {
return thismonth;
}
}
});
Basically I’m comparing a date that the user submits through a form that is formatted as yyyy-mm-dd to new Date() and then picking out the different parts so I can style them differently.