Hi everyone
It´s been a while since my last post in the community
I have a couple of questions regarding operations with dates (I didn´t find a solution on the community thad doesn´t use API´s)
I need to pick a date and do some maths with it and then show the results in other labels
Example: I selected 2021-10-21
Then:
Label 1: 2021-10-21 + 5= 2021-10-26
Label 2: 2021-10-26 (result of the previous operation) + 10= 2021-11-05
Of course ther is two “problems”. Wich blocks I need to use? How can I do the maths with months (Feb has 28 days, etc.)?
And my second question is… Is it possible to “translate” dates using block “date imput” into other lenguages? June → Junio (Spanish)
The first line ThunkableWebviewerExtension.receiveMessage(function(message) { is the Thunkable Extension that reads the data passed from the app to the Web Viewer using the Post Message block. This line requires a call back function which is why you see function(message). The data passed from the app is in the message variable.
The second line const dateObj = JSON.parse(message); is creating a variable in JS that receives the data sent from the app and treat it as JSON object.
The third line const myDate = new Date(dateObj[0], dateObj[1] - 1, dateObj[2]); is creating a variable in JS to hold a date object using the properties passed from the app inside the JSON object.
The forth line myDate.setDate(myDate.getDate() + dateObj[3]); adjusting the date object by adding to it the last property of the JSON object passed from the app.
The last line ThunkableWebviewerExtension.postMessage(myDate); is another Thunkable extension to send data from the JS code back to the app which will be received by the Receive Message block