diff --git a/src/public/google-blockly/own/blocks_time.js b/src/public/google-blockly/own/blocks_time.js index 3f670444e..30a005dc6 100644 --- a/src/public/google-blockly/own/blocks_time.js +++ b/src/public/google-blockly/own/blocks_time.js @@ -465,7 +465,7 @@ Blockly.Blocks['time_get_special'] = { this.setInputsInline(true); - this.setOutput(true); + this.setOutput(true, 'Number'); this.setColour(Blockly.Time.HUE); this.setTooltip(Blockly.Translate('time_get_special_tooltip')); @@ -545,4 +545,82 @@ Blockly.JavaScript['time_astro'] = function(block) { const offset = parseFloat(block.getFieldValue('OFFSET')); return [`getAstroDate('${type}', undefined, ${offset})`, Blockly.JavaScript.ORDER_ATOMIC]; -}; \ No newline at end of file +}; + +// --- time calculation -------------------------------------------------- +Blockly.Time.blocks['time_calculation'] = + '' + + ' ' + + ' ' + + ' object' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 1' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; + +Blockly.Blocks['time_calculation'] = { + init: function() { + this.appendDummyInput('NAME') + .appendField(Blockly.Translate('time_calculation')); + + this.appendValueInput('DATE_TIME') + .appendField(Blockly.Translate('time_calculation_on')) + .setCheck(null); + + this.appendDummyInput('OPERATION') + .appendField(new Blockly.FieldDropdown([ + ['+', '+'], + ['-', '-'], + ]), 'OPERATION'); + + this.appendValueInput('VALUE'); + + this.appendDummyInput('UNIT') + .appendField(new Blockly.FieldDropdown([ + [Blockly.Translate('time_calculation_ms'), 'ms'], + [Blockly.Translate('time_calculation_sec'), 'sec'], + [Blockly.Translate('time_calculation_min'), 'min'], + [Blockly.Translate('time_calculation_hour'), 'hour'], + [Blockly.Translate('time_calculation_day'), 'day'], + [Blockly.Translate('time_calculation_week'), 'week'], + ]), 'UNIT'); + + this.setInputsInline(true); + + this.setOutput(true, 'Number'); + + this.setColour(Blockly.Time.HUE); + this.setTooltip(Blockly.Translate('time_calculation_tooltip')); + this.setHelpUrl(Blockly.Translate('time_calculation_help')); + }, +}; + +Blockly.JavaScript['time_calculation'] = function(block) { + const dateTime = Blockly.JavaScript.valueToCode(block, 'DATE_TIME', Blockly.JavaScript.ORDER_ATOMIC); + const operation = block.getFieldValue('OPERATION'); + const value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_ATOMIC); + const unit = block.getFieldValue('UNIT'); + + let step = 1; + if (unit === 'sec') { + step = 1000; + } else if (unit === 'min') { + step = 60 * 1000; + } else if (unit === 'hour') { + step = 60 * 60 * 1000; + } else if (unit === 'day') { + step = 24 * 60 * 60 * 1000; + } else if (unit === 'week') { + step = 7 * 24 * 60 * 60 * 1000; + } + + return [`/* time calculation */ ((dateTime) => { const ts = (typeof dateTime === 'object' ? dateTime.getTime() : dateTime); return ts ${operation} ((${value}) * ${step}); })(${dateTime})`, Blockly.JavaScript.ORDER_ATOMIC]; +}; diff --git a/src/public/google-blockly/own/blocks_words.js b/src/public/google-blockly/own/blocks_words.js index a0c6c03eb..5c0f4d9e4 100644 --- a/src/public/google-blockly/own/blocks_words.js +++ b/src/public/google-blockly/own/blocks_words.js @@ -303,6 +303,16 @@ Blockly.Words['time_get_special_month_start'] = {'en': 'Start of month', Blockly.Words['time_get_special_month_end'] = {'en': 'End of month', 'de': 'Ende des Monats', 'ru': 'Конец месяца', 'pt': 'Fim do mês', 'nl': 'Einde maand', 'fr': 'Fin du mois', 'it': 'Fine del mese', 'es': 'Fin del mes', 'pl': 'Koniec miesiąca', 'zh-cn': '月底', 'uk': 'Кінець місяця'}; Blockly.Words['time_get_special_tooltip'] = {'en': 'Calculate time stamps', 'de': 'Zeitstempel berechnen', 'ru': 'Рассчитать метки времени', 'pt': 'Calcular selos de tempo', 'nl': 'Vertaling:', 'fr': 'Calculer les timbres horaires', 'it': 'Calcola i timestamp', 'es': 'Calcular sellos de tiempo', 'pl': 'Kalkulacja', 'zh-cn': '定时邮票', 'uk': 'Розрахунок штампів часу'}; Blockly.Words['time_get_special_help'] = {'en': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'de': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'ru': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'pt': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'nl': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'fr': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'it': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'es': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'pl': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'zh-cn': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'uk': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md'}; +Blockly.Words['time_calculation'] = {'en': 'Calculate time', 'de': 'Zeit berechnen', 'ru': 'Рассчитать время', 'pt': 'Calcular o tempo', 'nl': 'Bereken de tijd', 'fr': 'Temps de calcul', 'it': 'Calcola il tempo', 'es': 'Calcular tiempo', 'pl': 'Czas kalendarzowy', 'zh-cn': '时间', 'uk': 'Розрахунок часу'}; +Blockly.Words['time_calculation_on'] = {'en': 'based on', 'de': 'basierend auf', 'ru': 'на основе', 'pt': 'baseado em', 'nl': 'gebaseerd op', 'fr': 'basée sur', 'it': 'sulla base', 'es': 'basado en', 'pl': 'na podstawie', 'zh-cn': '基础', 'uk': 'на основі'}; +Blockly.Words['time_calculation_ms'] = {'en': 'ms', 'de': 'ms', 'ru': 'мс', 'pt': 'ms', 'nl': 'Mevrouw', 'fr': 'Mme', 'it': 'Signorina', 'es': 'Sra', 'pl': 'ms', 'zh-cn': '毫秒', 'uk': 'РС'}; +Blockly.Words['time_calculation_sec'] = {'en': 'sec', 'de': 'Sek', 'ru': 'сек.', 'pt': 'seg', 'nl': 'sec', 'fr': 'seconde', 'it': 'secondo', 'es': 'segundo', 'pl': 'sec', 'zh-cn': '秒', 'uk': 'сек'}; +Blockly.Words['time_calculation_min'] = {'en': 'min', 'de': 'Min', 'ru': 'мин.', 'pt': 'min', 'nl': 'min', 'fr': 'min', 'it': 'min', 'es': 'min', 'pl': 'min', 'zh-cn': '分', 'uk': 'хв'}; +Blockly.Words['time_calculation_hour'] = {'en': 'hours', 'de': 'Stunden', 'ru': 'часов', 'pt': 'horas', 'nl': 'uren', 'fr': 'heures', 'it': 'ore', 'es': 'horas', 'pl': 'godzin', 'uk': 'час', 'zh-cn': '小时', }; +Blockly.Words['time_calculation_day'] = {'en': 'days', 'de': 'Tage', 'ru': 'дней', 'pt': 'dias', 'nl': 'dagen', 'fr': 'jours', 'it': 'giorni', 'es': 'días', 'pl': 'dni', 'zh-cn': '日 日', 'uk': 'днів'}; +Blockly.Words['time_calculation_week'] = {'en': 'weeks', 'de': 'Wochen', 'ru': 'недели', 'pt': 'semanas', 'nl': 'weken', 'fr': 'semaines', 'it': 'settimane', 'es': 'semanas', 'pl': 'tydzień', 'uk': 'тижнів', 'zh-cn': '星期', }; +Blockly.Words['time_calculation_tooltip'] = {'en': 'Add or substract time', 'de': 'Zeit hinzufügen oder subtrahieren', 'ru': 'Добавьте или затрудните время', 'pt': 'Adicionar ou subtrair tempo', 'nl': 'Advies of substracte tijd', 'fr': 'Temps d\'ajout ou de sous-traitance', 'it': 'Aggiungere o substrarsi il tempo', 'es': 'Tiempo de adición o subcontrato', 'pl': 'Addd lub Substract time', 'uk': 'Додати або підстрактний час', 'zh-cn': '增加或说明时间', }; +Blockly.Words['time_calculation_help'] = {'en': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'de': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'ru': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'pt': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'nl': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'fr': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'it': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'es': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'pl': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'zh-cn': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md', 'uk': 'https://github.com/ioBroker/ioBroker.telegram/blob/master/README.md'}; // --- TIMEOUTS -------------------------------------------------- Blockly.Words['Timeouts'] = {'en': 'Timeouts', 'de': 'Timeouts', 'ru': 'Timeouts', 'pt': 'Timeouts', 'nl': 'Time-outs', 'fr': 'Délais', 'it': 'Timeout', 'es': 'Tiempos de espera', 'pl': 'Timeouts', 'zh-cn': '定时器', 'uk': 'Тайм-аути'};