MagicMirror² v2.7.0 is available! For more information about this release, check out this topic.

Default Calendar module // request to show events only if start date > today + 2 days



  • Hi,

    Is there a way to make the calendar events show only when they are after after a certain number of days?

    Let’s say, do not show an event if date is < today + 2 days.

    I tried to use the ExcludedEvents + FilterBy “until” but didn’t worked.
    Also looked at modifying the calendar or fetcher.js but sounds like a bad idea…

    Regards

    Regards



  • you can try to use this

    			config: {
    				fetchInterval: 60000,
    				maximumEntries: 15, // you can also change this to 2 to have the first 2 entries only
    				maximumNumberOfDays: 365, //change this to 2 it should limit the max number of days in the future to 2
    				animationSpeed: 0,
    				fadePoint: 3,
    				timeFormat: 'absolute',
    				dateformat: 'dddd Do MMM',
    				urgency: 3,
    				calendars:
    

    Let me know if it works out



  • hi @ganget
    Thanks for prompt reply.

    Maybe there is a misunderstanding as I can’t figure out what is forcing the calendar to start in 2 days only in your calendar.

    Your code will allow me to block max entries to 15 or to a certain number of days (365 or 2 or whatever) but not allow me to hide event from today + the day after.

    Let me try to rephrase my need : I need the calendar to hide (to not show) the 2 first days of event.

    Or maybe I missed something in your code.



  • No you did not miss anything in my code i just misinterpreted your question. Sorry for that here is another idea that could work. Maybe the continue statement will help you to skip the 2 first entries of the calendar. You will need to change the module code for that to work.



  • @ganget
    no problem. thanks for the idea.
    I was thinking about modifying the module code to change “today’s” date into “today’s date +2” but can’t yet figure out how too.



  • @bolish

    the existing code is.

    	if (event.startDate >= new Date()) {
    

    and ideas on how to add days to today or whatever

    https://stackoverflow.com/questions/3818193/how-to-add-number-of-days-to-todays-date



  • @sdetweil
    Thanks, I will give it a try this evening and keep you guys posted.



  • @sdetweil
    Hi again, I just tried by modifying the createEventList “today” and “now” variable, but it didn’t work…

    createEventList: function () {
    		var events = [];
    		var someDate = new Date();
    		var numberOfDaysToAdd = 6;
    		someDate.setDate(someDate.getDate() + numberOfDaysToAdd);
    		var today = moment(someDate).startOf("day");
    		var now = someDate;
    		for (var c in this.calendarData) {
    


  • @bolish close…

    the existing loop takes ALL events, just checking to see if each event is TODAY (sets a flag)

    to eliminate them you need one more test (in addition to the rest of your code above)

    		var someDate = new Date();
    		var numberOfDaysToAdd = 6;
    		someDate.setDate(someDate.getDate() + numberOfDaysToAdd);
    		var today = moment(someDate).startOf("day");
    	//var today = moment().startOf("day");
    		for (var c in this.calendarData) {
    			var calendar = this.calendarData[c];
    			for (var e in calendar) {
    				var event = calendar[e];
                                     // if event happens further away than x number of days (6 in this sample)
    				if(event.startDate>= today) {    < ------
    					if(this.config.hidePrivate) {
    						if(event.class === "PRIVATE") {
    							  // do not add the current event, skip it
    							  continue;
    						}
    					}
    					event.url = c;
    					event.today = event.startDate >= today && event.startDate < (today + 24 * 60 * 60 * 1000);
    					events.push(event);
    				}
    			}
    		}
    


  • @sdetweil
    Works like a charm.
    Thank you very much, I’ve learnt something thanks to you and appreciated your support for debug.
    See you around.