<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Read dates from file and do a compare]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I need some help with a module I’m trying do develop. I need to read data from a *.json and compare the data with current date. If one or more of data are equal to current date, it will show a picture otherwise it doesn’t.<br />
I think the date must be stored in a *.json file and read with NODE_HELPER.JS. But I can’t get it to work.</p>
<p dir="auto">Example. Of *.JSON file:</p>
<pre><code>{
Case1 [
“21.02.2021”,
“25.02.2021”,
“28.02.2021”
]
Case2 [
“12.03.2021”,
“23.03.2021”,
“29.04.2021”
]
}
</code></pre>
<p dir="auto">Or another example.</p>
<pre><code>{
“case1” , “21.02.2021”,
“case1” , “25.02.2021”,
“case1” , “28.02.2021”,
“case2” , “12.03.2021”,
“case2” , “23.03.2021”,
“case2” , “29.04.2021
]
}
</code></pre>
<p dir="auto">I have tried to do a read command, but I’m not able to see if it can read the file correct or even find the file that I’m trying to read in.</p>
<p dir="auto">So can someone help me with a working example of reading from a file and do the compare?</p>
]]></description><link>https://forum.magicmirror.builders/topic/14560/read-dates-from-file-and-do-a-compare</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 19:02:53 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/14560.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Feb 2021 12:26:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Read dates from file and do a compare on Sun, 07 Feb 2021 15:09:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a></p>
<p dir="auto">Thanks for all the help.<br />
I ended the project  because I found a module that allready hat the function that I was looking for.</p>
<p dir="auto">You came up with some good information, thx for the help.</p>
]]></description><link>https://forum.magicmirror.builders/post/88157</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88157</guid><dc:creator><![CDATA[BravoOscar]]></dc:creator><pubDate>Sun, 07 Feb 2021 15:09:46 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Thu, 04 Feb 2021 08:32:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bravooscar" aria-label="Profile: bravooscar">@<bdi>bravooscar</bdi></a> u are usuing object.keys() to.loop.over the array  this only gives u unique entries, house, …</p>
<p dir="auto">i would  use my loop, which covers every entry.<br />
i dont understand your file data</p>
]]></description><link>https://forum.magicmirror.builders/post/88117</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88117</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 04 Feb 2021 08:32:07 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Thu, 04 Feb 2021 06:18:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a><br />
That I know. I allready have the actual date and the date from the array,<br />
Im unsure of how to get all the dates and all the types from the array, so if there are more of the same dates, then there are more types taht has to be displayed.</p>
]]></description><link>https://forum.magicmirror.builders/post/88116</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88116</guid><dc:creator><![CDATA[BravoOscar]]></dc:creator><pubDate>Thu, 04 Feb 2021 06:18:58 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Wed, 03 Feb 2021 22:56:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bravooscar" aria-label="Profile: bravooscar">@<bdi>bravooscar</bdi></a> as i said u can use the js library moment().format(‘dd.mm.yyyy’) to get today in string to compare</p>
<p dir="auto">see the online doc for exact syntax</p>
]]></description><link>https://forum.magicmirror.builders/post/88112</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88112</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 03 Feb 2021 22:56:12 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Wed, 03 Feb 2021 22:24:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a></p>
<p dir="auto">I have this now, and this is working.</p>
<pre><code>for(let type of Object.keys(obj)){
var date = obj[type];
console.log(type, date);
}
</code></pre>
<p dir="auto">This will show the correct type and date.<br />
But I have something in mind, that look like this:</p>
<pre><code>if date === currentdate {
picture=type+"Div"}

ex:  
20.02.2021 === 20.02.2021 then var piture= "bigDiv"
</code></pre>
<p dir="auto">picture is then displayed.</p>
<p dir="auto">but this have to be a loop, because there can be same dates but with different types(pictures)</p>
<p dir="auto">Does this gives any meaning? its hard to descripe, but I’m realy glad for all the help I get.</p>
]]></description><link>https://forum.magicmirror.builders/post/88111</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88111</guid><dc:creator><![CDATA[BravoOscar]]></dc:creator><pubDate>Wed, 03 Feb 2021 22:24:12 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Wed, 03 Feb 2021 02:05:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bravooscar" aria-label="Profile: bravooscar">@<bdi>bravooscar</bdi></a></p>
<pre><code>for( let entry of object.RecylingDates){
  if (entry.Type ==='House'){
      if(entry.Date==='........'){
      }
   }
}
</code></pre>
<p dir="auto">you can use moment().format(???)<br />
where ??? is the layout of yiur date strings to get something for today, tomorrow…</p>
]]></description><link>https://forum.magicmirror.builders/post/88096</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88096</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 03 Feb 2021 02:05:12 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Tue, 02 Feb 2021 22:27:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a></p>
<p dir="auto">It now works, I can get data into my new object.</p>
<p dir="auto">My new json file look like this:</p>
<pre><code>{
  "RecyclingDates": [
{ "Type": "House", "Date": "02.01.2021"},
{ "Type": "House", "Date": "08.01.2021"},
{ "Type": "House", "Date": "15.01.2021"},
{ "Type": "Glass", "Date": "22.01.2021"},
{ "Type": "Glass", "Date": "29.01.2021"},
{ "Type": "Glass", "Date": "05.02.2021"},
{ "Type": "Garden", "Date": "12.02.2021"},
{ "Type": "Garden", "Date": "19.02.2021"},
{ "Type": "Garden", "Date": "26.02.2021"},
{ "Type": "Garden", "Date": "05.03.2021"},
{ "Type": "Big", "Date": "12.03.2021"},
{ "Type": "Big", "Date": "19.03.2021"},
{ "Type": "Big", "Date": "26.03.2021"}
]
}
</code></pre>
<p dir="auto">I get this object output:</p>
<pre><code>Object
RecyclingDates: Array(13)
0:
Type: "House"
Date: "02.01.2021"
__proto__: Object
1:
Type: "House"
Date: "08.01.2021"
__proto__: Object
2: {Type: "House", Date: "15.01.2021"}
3: {Type: "Glass", Date: "22.01.2021"}
4: {Type: "Glass", Date: "29.01.2021"}
5: {Type: "Glass", Date: "05.02.2021"}
6: {Type: "Garden", Date: "12.02.2021"}
7: {Type: "Garden", Date: "19.02.2021"}
8: {Type: "Garden", Date: "26.02.2021"}
9: {Type: "Garden", Date: "05.03.2021"}
10: {Type: "Big", Date: "12.03.2021"}
11: {Type: "Big", Date: "19.03.2021"}
12: {Type: "Big", Date: "26.03.2021"}
length: 13
</code></pre>
<p dir="auto">I opend “0” and “1” in the object, so you can see how its stored in the object.</p>
<p dir="auto">How do I access these values in my module.js file. I hope to make a loop/compare of the array.<br />
My plan is to show different  pictures according to the Type and if the Date is equale to current date.</p>
]]></description><link>https://forum.magicmirror.builders/post/88095</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88095</guid><dc:creator><![CDATA[BravoOscar]]></dc:creator><pubDate>Tue, 02 Feb 2021 22:27:46 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Tue, 02 Feb 2021 00:05:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bravooscar" aria-label="Profile: bravooscar">@<bdi>bravooscar</bdi></a></p>
<p dir="auto">full node_helper.js above, tested, working<br />
need to get path to file in module folder (not current folder)</p>
<p dir="auto">sends object to module to make decisions on what to display</p>
]]></description><link>https://forum.magicmirror.builders/post/88081</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88081</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 02 Feb 2021 00:05:50 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Mon, 01 Feb 2021 22:10:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bravooscar" aria-label="Profile: bravooscar">@<bdi>bravooscar</bdi></a> compare back in modulename.js, it needs to decide.</p>
<p dir="auto">trigger<br />
just say nothing happens in node helper without some event</p>
<p dir="auto">this should get the file contents and send to modulename.</p>
<p dir="auto">modulename.js sends socketNotification to helper w config info to start the process</p>
]]></description><link>https://forum.magicmirror.builders/post/88080</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88080</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Mon, 01 Feb 2021 22:10:21 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Mon, 01 Feb 2021 22:07:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a></p>
<p dir="auto">What do you meen by " <em>need some trigger function</em>"? is that in the node_helper.js or where should it be?</p>
<p dir="auto"><em>modulename.js sends node_helper a socket notification w the module config info<br />
node_helper sends the data back as object</em><br />
Should I write some code in the modulename.js that call file read or do you mean that this is the place to make the compare?</p>
]]></description><link>https://forum.magicmirror.builders/post/88079</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88079</guid><dc:creator><![CDATA[BravoOscar]]></dc:creator><pubDate>Mon, 01 Feb 2021 22:07:05 GMT</pubDate></item><item><title><![CDATA[Reply to Read dates from file and do a compare on Tue, 02 Feb 2021 00:04:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bravooscar" aria-label="Profile: bravooscar">@<bdi>bravooscar</bdi></a><br />
in node_helper.js</p>
<pre><code>var NodeHelper = require("node_helper");
const fs = require('fs')
const path = require('path')
// add require of other javascripot components here
// var xxx = require('yyy') here

module.exports = NodeHelper.create({


	// handle messages from our module// each notification indicates a different messages
	// payload is a data structure that is different per message.. up to you to design this
	socketNotificationReceived(notification, payload) {
		console.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
		// if config message from module
		if (notification === "CONFIG") {
			// save payload config info
			this.config=payload
			let p = path.resolve('.','modules',this.name,this.config.filename)
			console.log("file="+p)
			fs.readFile(p, (error,filedata)=&gt; {
			console.log("filedata="+filedata)
			let data =JSON.parse(filedata)
			this.sendSocketNotification('filedata', data)
			})
		}
	},
});
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/88059</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/88059</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 02 Feb 2021 00:04:05 GMT</pubDate></item></channel></rss>