Initial commit
This commit is contained in:
commit
c53c7085bc
60 changed files with 23885 additions and 0 deletions
54
flow/check_if_new_day.js
Normal file
54
flow/check_if_new_day.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
exports.id = 'checknewday';
|
||||
exports.title = 'Check if new day';
|
||||
exports.group = 'Worksys';
|
||||
exports.color = '#5D9CEC';
|
||||
exports.version = '0.0.1';
|
||||
exports.output = ['white'];
|
||||
exports.input = true;
|
||||
exports.author = 'Rastislav Kovac';
|
||||
exports.icon = 'cloud-upload';
|
||||
|
||||
exports.readme = `Checks, if day changed. If yes, it sends it to connected components`;
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const weekday = ["Nedele","Pondeli","Uteri","Streda","Ctvrtek","Patek","Sobota"];
|
||||
|
||||
function getDate() {
|
||||
// for some reason new Date() function does not set month and year in local timezone, so we use "timedatectl" command
|
||||
let dateFromCommand = execSync("timedatectl", {}).toString();
|
||||
|
||||
let first = dateFromCommand.search("time:");
|
||||
let last = dateFromCommand.search(" CE");
|
||||
dateFromCommand = dateFromCommand.slice(first, last); //Thu 2022-04-07 13:38:03
|
||||
|
||||
const d = new Date(dateFromCommand);
|
||||
return d;
|
||||
}
|
||||
|
||||
exports.install = function(instance) {
|
||||
|
||||
let date = null;
|
||||
|
||||
const checkNewDay = () =>
|
||||
{
|
||||
const d = getDate();
|
||||
const today = d.getDate(); //napr 21 (dvadsiateho prveho)
|
||||
|
||||
if(today !== date)
|
||||
{
|
||||
date = today;
|
||||
const month = d.getMonth(); // 0-11
|
||||
const day = d.getDay(); // 0-6 (0 = nedela)
|
||||
const datum = `${today}.${month + 1}`;
|
||||
|
||||
const result = [datum, weekday[day]];
|
||||
instance.send(0, result); // ['22.12', 'Streda']
|
||||
}
|
||||
}
|
||||
|
||||
instance.on('data', flowdata => {
|
||||
checkNewDay();
|
||||
})
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue