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

Is there a way to show specific compliments on specific dates?



  • @romain sounds logic. but i dont have any knowledge about javascript. so i have to start from scratch. i dont know…i think for now your workaround sounds best 😃



  • @pauabaer as you dont have coding experience I guess you have neither experience with git. By modifying the files you will not be able to easily update the magicmirror.



  • @strawberry-3-141 you are right. i have read about this and i am aware of that fact. means a default function would be better. so i hope @romain can overcome the laziness 🕶

    ps @romain i hope you know how i meant this. you do what you want to do. because i dont have any coding experience i can only speak out some wishes/ features to make this project (for more people) a bit more “magically”.



  • @pauabaer sure, however, I have other projects to work on so I rather focus on them. I don’t have that much knowledge in javascipt either. (I do have some knowledge in other language though). When I do stuff it’s a lot a trial and error until that work (even for the tiny bit of code I made in this post required some research from me. Not a lot of it… but some. I never used the moments() function before)
    This is your opportunity to gain knowledge.



  • @romain I live in Germany, at the time I posted it was already the 27th here 🙂 It still does not work, even though now it is the 27th pretty much everywhere in the world. Do you have any idea what might be the reason when you look at the code I posted?



  • @CyanKali I live in french so it should be pretty much the same date. Try debugging.
    add the following line just before the if
    console.log('The date is : "' + moment().format('MMM D , h:mm a')+'"')
    Then run the mirror in dev mode . (go into the MagicMirror folder and run DISPLAY=:0 npm start dev) choose the tab “console”. And wait to see the message “the date is blablabla” apear and copy past the message here so we know what your magic mirror think the date is. Maybe it think your on the united state or something
    If that the case I don’t know how to tell moments to check the date from another country. you might want to change the function then.

    Search “how to get the date from a specific country in jacascript” on google and you might find the right function to do it.
    The only thing you have to know is that the " == " mean “equal”. The if mean that if the left part of the operation is equal to the right part, then you do the line bellow.
    So you need to replace the moment thing by another function.

    Maybe someone in this forum now how to tell moment the timezone it have to use



  • @romain I figured it out! The console showed me it was April 29 today (which is the right date), but it was written as “Apr. 29”, so with a dot behind the month. I tried writing it like this in the code and now it works!
    So it has to be:

    if (moment().format('MMM D') == 'Apr. 29')
    

    and then it works 🙂
    And now I know how to run my mirror in dev mode, which will be useful in the future 😉 Thank you!



  • @CyanKali Great 😃 . I guess that for some reason your moment.js doesn’t print the same thing as mine x) (which is kinda weird but fine)



  • @romain moment uses different locales for dates and so on based on the language set



  • In case someone is still wondering how to simply display set compliments on set days: ```

    complimentArray: function() {
    		var hour = moment().hour();
    		var date = moment().format('DDMM');  \\add this into compliments.js
    		var compliments;
    
    		if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
    			compliments = this.config.compliments.morning.slice(0);
    		} else if (hour >= this.config.afternoonStartTime && hour < this.config.afternoonEndTime && this.config.compliments.hasOwnProperty("afternoon")) {
    			compliments = this.config.compliments.afternoon.slice(0);
    		} else if(this.config.compliments.hasOwnProperty("evening")) {
    			compliments = this.config.compliments.evening.slice(0);
    		}
    
    		if (typeof compliments === "undefined") {
    			compliments = new Array();
    		}
    		
    
    		if (this.currentWeatherType in this.config.compliments) {
    			compliments.push.apply(compliments, this.config.compliments[this.currentWeatherType]);
    		}
    
      	    if (date in this.config.compliments) {
    			compliments.push.apply(compliments, this.config.compliments[date]);
    		} \\add these 3 lines into compliments.js
    
    		compliments.push.apply(compliments, this.config.compliments.anytime);
    
    		return compliments;
    	}, 
    

    Example:

    anytime: [
    				"Hey there sexy!"
    			],
    			morning: [
    				"Good morning, handsome!",
    				"Enjoy your day!",
    				"How was your sleep?"
    			],
    			afternoon: [
    				"Hello, beauty!",
    				"You look sexy!",
    				"Looking good today!"
    			],
    			"1005": [
    				"Today is May 10th",
    				"You look nice!",
    				"Hi, sexy!"
    			] 
    		},
    

    EDIT:
    Anyone know how to show compliments on days without a set date each year, like Christmas, but something like the second Sunday of May, like Mother’s day?