API domogeek perds les infos tout le temps

Euh non, ce n’est pas évident pour férié notamment…
En cherchant sur Internet, j’ai trouvé un code pour Nodered :slight_smile: Determine properties like holiday, business day, weekend, etc at the moment when message is received. (flow) - Node-RED adapté à la Slovénie :frowning:

Mais, au moins en France, les dates des jours fériés sont soient fixes soient dépendent de Pâques, j’ai adapté son code à la France.
J’ai également rajouté un « shift » pour avoir les infos sur un autre jour.

Et donc, en demandant la date 398 jours en arrière par rapport à aujourd’hui (2/2/21)
{ "_msgid":"6f5a1fc9.560d2", "payload":-398,"date":"2020-01-01T22:23:37.374Z", "holiday":true, "businessday":false, "weekend":false, "weekday":3, "leapyear":true, "holiday_name":"Jour de l'an", "properties":"holiday=true,businessday=false,weekend=false,weekday=3,leapyear=true" }

On voit que le 1er janvier 2020 est un jour férié et que c’était un mercredi…

Ou plus simplement pour demain (donc msg.payload égale 1):

[{"id":"18bb465c.d91d9a","type":"function","z":"f5b50430.ea48b8","name":"Propriété de la date","func":"/*\n\n * ----------------------------------------------------------------------------\n * \"THE BEER-WARE LICENSE\" (Revision 42):\n * github.com/mrizvic wrote this file.  As long as you retain this notice you\n * can do whatever you want with this stuff. If we meet some day, and you think\n * this stuff is worth it, you can buy me a beer in return.   M.Rizvic\n * ----------------------------------------------------------------------------\n * Avec une adaptation de R.Giraud pour la France - Mais ça ne mérite pas une bière\n * avec en plus la possibilté via msg.payload de demander une autre date + ou - X jours\n * par rapport à aujourd'hui\n\n## This function will pass incoming message to multiple outputs based on following conditions:\n## output 1 - unconditional\n## output 2 - if its holiday\n## output 3 - if its business day\n## output 4 - if its weeekend\n## output 5 - if its leap year\n\n## Holidays are defined in a matter of if..else if sentences as shown below in USER SPECIFIC DATES section. Some holidays are variable and must be calculated each time (e.g. easter)\n## Some properties will be appended to original message in case some would like to use them. Below is an example:\n\n_msgid: \"78a5e9f0.a318e8\"\ntopic: \"\"\npayload: 4\ndate: \"2017-02-23T15:59:59.401Z\"\nholiday: false\nbusinessday: true\nweekend: false\nweekday: 4\nleapyear: false\nproperties: \"holiday=false,businessday=true,weekend=false,weekday=4,leapyear=false\"\n\nweekday numbers are in range from 1 to 7 where is 1 for monday, 2 for tuesday, ... and 7 for sunday\ntariff can be 'vt' (high tariff) or 'mt' (low tariff)\n*/\n\nvar futur = msg.payload;\n// take current timestamp\nvar today = new Date();\nvar date = today.addDays(futur);\n\nvar getEasterDate = function(year) {\n  var a = year % 19;\n  var b = Math.floor(year / 100);\n  var c = year % 100;\n  var d = Math.floor(b / 4);\n  var e = b % 4;\n  var f = Math.floor((b + 8) / 25);\n  var g = Math.floor((b - f + 1) / 3);\n  var h = (19 * a + b - d - g + 15) % 30;\n  var i = Math.floor(c / 4);\n  var k = c % 4;\n  var l = (32 + 2 * e + 2 * i - h - k) % 7;\n  var m = Math.floor((a + 11 * h + 22 * l) / 451);\n  var n0 = (h + l + 7 * m + 114);\n  var n = Math.floor(n0 / 31) - 1;\n  var p = n0 % 31 + 1;\n  var date = new Date(year,n,p);\n  return date;\n};\n\nDate.prototype.addDays = function(days)\n{\n    var dat = new Date(this.valueOf());\n    dat.setDate(dat.getDate() + days);\n    return dat;\n};\n\nvar weekday = date.getDay();\nif (weekday === 0) { weekday = 7; }\n\nvar year = date.getFullYear();\nvar month = date.getMonth() + 1;\nvar day = date.getDate();\nvar hour = date.getHours();\n\nvar isHoliday = false;\nvar holidayString = \"\";\nvar isLeapYear = new Date(year, 1, 29).getMonth() == 1;\n\n// sunday or saturday\nvar isWeekend = (weekday > 5);\nvar isBusinessDay = ! isWeekend;\n\n\n// USER SPECIFIC DATES - BEGIN\n\n// Dimanche de Pâques\nvar easterDate = getEasterDate(year);\nvar ed1 = easterDate.getDate();\nvar em1 = easterDate.getMonth() + 1;\n\n// Lundi de Pâques\nvar easterMonday = easterDate.addDays(1);\nvar ed2 = easterMonday.getDate();\nvar em2 = easterMonday.getMonth() + 1;\n\n// Ascension = (Dimanche de Pâques + 39)\nvar ascension = easterDate.addDays(39);\nvar ad1 = ascension.getDate();\nvar am1 = ascension.getMonth() + 1;\n\n// Pentecôte\nvar pentecote = easterDate.addDays(50);\nvar pd1 = pentecote.getDate();\nvar pm1 = pentecote.getMonth() + 1;\n\n// set date specific properties\n\n     if ( (month == 1)   && (day == 1)   ) { isHoliday = true; isBusinessDay = false; holidayString = \"Jour de l'an\"; }\nelse if ( (month == em1) && (day == ed1) ) { isHoliday = true; isBusinessDay = false; holidayString = \"Dimanche de Pâques\"; }\nelse if ( (month == em2) && (day == ed2) ) { isHoliday = true; isBusinessDay = false; holidayString = \"Lundi de Pâques\"; }\nelse if ( (month == 5)   && (day == 1)   ) { isHoliday = true; isBusinessDay = false; holidayString = \"Premier mai\"; }\nelse if ( (month == 5)   && (day == 8)   ) { isHoliday = true; isBusinessDay = false; holidayString = \"Armistice 39/45\"; }\nelse if ( (month == am1) && (day == ad1) ) { isHoliday = true; isBusinessDay = false; holidayString = \"Ascension\"; }\nelse if ( (month == pm1) && (day == pd1) ) { isHoliday = true; isBusinessDay = false; holidayString = \"Pentecôte\";}\nelse if ( (month == 7)   && (day == 14)  ) { isHoliday = true; isBusinessDay = false; holidayString = \"Fête Nationale\"; }\nelse if ( (month == 8)   && (day == 15)  ) { isHoliday = true; isBusinessDay = false; holidayString = \"Assomption\"; }\nelse if ( (month == 11)  && (day == 1)   ) { isHoliday = true; isBusinessDay = false; holidayString = \"Toussaint\"; }\nelse if ( (month == 11)  && (day == 11)  ) { isHoliday = true; isBusinessDay = false; holidayString = \"Armistice 14/18\"; }\nelse if ( (month == 12)  && (day == 25)  ) { isHoliday = true; isBusinessDay = false; holidayString = \"Noël\"; }\n\n// preserve original message\nvar result = msg;\nmsg.date = date;\n\n// add our properties\nresult.holiday = isHoliday;\nresult.businessday = isBusinessDay;\nresult.weekend = isWeekend;\nresult.weekday = weekday;\nresult.leapyear = isLeapYear;\nif (holidayString.length > 0) {\n  result.holiday_name = holidayString;\n}\n\n// generate string of properties so one could\n// parse using switch node\nresult.properties = '';\nresult.properties += 'holiday=' + isHoliday + ',';\nresult.properties += 'businessday=' + isBusinessDay + ',';\nresult.properties += 'weekend=' + isWeekend + ',';\nresult.properties += 'weekday=' + weekday + ',';\nresult.properties += 'leapyear=' + isLeapYear;\n\n// generate conditional outputs\nmsg = result;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":2460,"wires":[["bb47b7a1.f10398"]]},{"id":"6e1cf6e6.e7c138","type":"inject","z":"f5b50430.ea48b8","name":"Demain","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"1","payloadType":"num","x":210,"y":2460,"wires":[["18bb465c.d91d9a"]]},{"id":"bb47b7a1.f10398","type":"debug","z":"f5b50430.ea48b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":2460,"wires":[]}]

A adapter pour la Belgique avec les jours fériés locaux :slight_smile: