Skip to content

Commit

Permalink
Day of week as number always returns 1 (monday) to 7 (sunday)
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Dec 10, 2023
1 parent 305f8eb commit 21a1ddd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the
<!--
### **WORK IN PROGRESS**
-->
### **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)
Expand Down
36 changes: 18 additions & 18 deletions src/public/google-blockly/own/blocks_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/public/google-blockly/own/blocks_time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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 {
Expand Down

0 comments on commit 21a1ddd

Please sign in to comment.