Skip to content

Commit

Permalink
Added option for calendar week to Blockly
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Dec 18, 2023
1 parent bbcc5d6 commit 52e72a9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -48,6 +48,7 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the
-->
### **WORK IN PROGRESS**

* (klein0r) Added option for calendar week to Blockly
* (klein0r) Fixed inpaired round brackets of getMinutes (Blockly)

### 7.5.0 (2023-12-15)
Expand Down
3 changes: 3 additions & 0 deletions src/public/google-blockly/own/blocks_convert.js
Expand Up @@ -172,6 +172,7 @@ Blockly.Blocks.convert_from_date = {
[Blockly.Translate('time_get_wdt') , 'wdt'],
[Blockly.Translate('time_get_wdts') , 'wdts'],
[Blockly.Translate('time_get_wd') , 'wd'],
[Blockly.Translate('time_get_cw') , 'cw'],
[Blockly.Translate('time_get_custom') , 'custom'],
[Blockly.Translate('time_get_yyyy.mm.dd') , Blockly.Words['time_get_yyyy.mm.dd'] .format],
[Blockly.Translate('time_get_yyyy/mm/dd') , Blockly.Words['time_get_yyyy/mm/dd'] .format],
Expand Down Expand Up @@ -290,6 +291,8 @@ Blockly.JavaScript.convert_from_date = function (block) {
code = `formatDate(getDateObject(${value}), 'W', '${lang}')`;
} else if (option === 'wd') {
code = `(() => { const d = getDateObject(${value}).getDay(); return d === 0 ? 7 : d; })()`;
} else if (option === 'cw') {
code = `((date) => { const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())); const dayNum = d.getUTCDay() || 7; d.setUTCDate(d.getUTCDate() + 4 - dayNum); const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)); return Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7); })(getDateObject(${value}))`;
} else if (option === 'custom') {
code = `formatDate(getDateObject(${value}), '${format}')`;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/public/google-blockly/own/blocks_time.js
Expand Up @@ -314,6 +314,7 @@ Blockly.Blocks['time_get'] = {
[Blockly.Translate('time_get_wdt') , 'wdt'],
[Blockly.Translate('time_get_wdts') , 'wdts'],
[Blockly.Translate('time_get_wd') , 'wd'],
[Blockly.Translate('time_get_cw') , 'cw'],
[Blockly.Translate('time_get_custom') , 'custom'],
[Blockly.Translate('time_get_yyyy.mm.dd') , Blockly.Words['time_get_yyyy.mm.dd'] .format],
[Blockly.Translate('time_get_yyyy/mm/dd') , Blockly.Words['time_get_yyyy/mm/dd'] .format],
Expand Down Expand Up @@ -431,6 +432,8 @@ Blockly.JavaScript['time_get'] = function(block) {
code = `formatDate(new Date(), 'W', '${lang}')`;
} else if (option === 'wd') {
code = '(() => { const d = new Date().getDay(); return d === 0 ? 7 : d; })()';
} else if (option === 'cw') {
code = '((date) => { const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())); const dayNum = d.getUTCDay() || 7; d.setUTCDate(d.getUTCDate() + 4 - dayNum); const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)); return Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7); })(new Date())';
} else if (option === 'custom') {
code = `formatDate(new Date(), '${format}')`;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/public/google-blockly/own/blocks_words.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52e72a9

Please sign in to comment.