diff --git a/README.md b/README.md index 8e8782d31..0d7fc4717 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,10 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the +### **WORK IN PROGRESS** + +* (klein0r) Day of week as number always returns 1 (monday) to 7 (sunday) + ### 7.4.0 (2023-12-08) * (klein0r) Download script as xml file (export) diff --git a/src/public/google-blockly/own/blocks_convert.js b/src/public/google-blockly/own/blocks_convert.js index b8e122821..e77569774 100644 --- a/src/public/google-blockly/own/blocks_convert.js +++ b/src/public/google-blockly/own/blocks_convert.js @@ -259,41 +259,41 @@ Blockly.JavaScript.convert_from_date = function (block) { let code; if (option === 'object') { - code = 'getDateObject(' + value + ').getTime()'; + code = `getDateObject(${value}).getTime()`; } else if (option === 'ms') { - code = 'getDateObject(' + value + ').getMilliseconds()'; + code = `getDateObject(${value}).getMilliseconds()`; } else if (option === 's') { - code = 'getDateObject(' + value + ').getSeconds()'; + code = `getDateObject(${value}).getSeconds()`; } else if (option === 'sid') { - code = '(function () { const v = getDateObject(' + value + '); return v.getHours() * 3600 + v.getMinutes() * 60 + v.getSeconds(); })()'; + code = `(() => { const v = getDateObject(${value}); return v.getHours() * 3600 + v.getMinutes() * 60 + v.getSeconds(); })()`; } else if (option === 'm') { - code = '(getDateObject(' + value + ').getMinutes())'; + code = `getDateObject(${value}).getMinutes())`; } else if (option === 'mid') { - code = '(function () { const v = getDateObject(' + value + '); return v.getHours() * 60 + v.getMinutes(); })()'; + code = `(() => { const v = getDateObject(${value}); return v.getHours() * 60 + v.getMinutes(); })()`; } else if (option === 'h') { - code = 'getDateObject(' + value + ').getHours()'; + code = `getDateObject(${value}).getHours()`; } else if (option === 'd') { - code = 'getDateObject(' + value + ').getDate()'; + code = `getDateObject(${value}).getDate()`; } else if (option === 'M') { - code = '(getDateObject(' + value + ').getMonth() + 1)'; + code = `(getDateObject(${value}).getMonth() + 1)`; } else if (option === 'Mt') { - code = 'formatDate(getDateObject(' + value + '), "OO", "' + lang + '")'; + code = `formatDate(getDateObject(${value}), 'OO', '${lang}')`; } else if (option === 'Mts') { - code = 'formatDate(getDateObject(' + value + '), "O", "' + lang + '")'; + code = `formatDate(getDateObject(${value}), 'O', '${lang}')`; } else if (option === 'y') { - code = 'getDateObject(' + value + ').getYear()'; + code = `getDateObject(${value}).getYear()`; } else if (option === 'fy') { - code = 'getDateObject(' + value + ').getFullYear()'; + code = `getDateObject(${value}).getFullYear()`; } else if (option === 'wdt') { - code = 'formatDate(getDateObject(' + value + '), "WW", "' + lang + '")'; + code = `formatDate(getDateObject(${value}), 'WW', '${lang}')`; } else if (option === 'wdts') { - code = 'formatDate(getDateObject(' + value + '), "W", "' + lang + '")'; + code = `formatDate(getDateObject(${value}), 'W', '${lang}')`; } else if (option === 'wd') { - code = 'getDateObject(' + value + ').getDay()'; + code = `(() => { const d = getDateObject(${value}).getDay(); return d === 0 ? 7 : d; })()`; } else if (option === 'custom') { - code = 'formatDate(getDateObject(' + value + '), "' + format + '")'; + code = `formatDate(getDateObject(${value}), '${format}')`; } else { - code = 'formatDate(getDateObject(' + value + '), "' + option + '")'; + code = `formatDate(getDateObject(${value}), '${option}')`; } return [code, Blockly.JavaScript.ORDER_ATOMIC]; diff --git a/src/public/google-blockly/own/blocks_time.js b/src/public/google-blockly/own/blocks_time.js index 39f54e065..817d70060 100644 --- a/src/public/google-blockly/own/blocks_time.js +++ b/src/public/google-blockly/own/blocks_time.js @@ -406,7 +406,7 @@ Blockly.JavaScript['time_get'] = function(block) { } else if (option === 's') { code = '(new Date().getSeconds())'; } else if (option === 'sid') { - code = '(new Date().getHours() * 3600 + new Date().getMinutes() * 60 + new Date().getSeconds())'; + code = '(() => { const v = new Date(); return v.getHours() * 3600 + v.getMinutes() * 60 + v.getSeconds(); })()'; } else if (option === 'm') { code = '(new Date().getMinutes())'; } else if (option === 'mid') { @@ -430,7 +430,7 @@ Blockly.JavaScript['time_get'] = function(block) { } else if (option === 'wdts') { code = `formatDate(new Date(), 'W', '${lang}')`; } else if (option === 'wd') { - code = '(new Date().getDay() === 0 ? 7 : new Date().getDay())'; + code = '(() => { const d = new Date().getDay(); return d === 0 ? 7 : d; })()'; } else if (option === 'custom') { code = `formatDate(new Date(), '${format}')`; } else {