Skip to content

Commit de8a6f3

Browse files
Fix script polling event and add date
1 parent 3d3e5aa commit de8a6f3

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

extensions/web-scripts/toolbox.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<block type="lha_clear_timer"></block>
2222
<block type="lha_to_string"></block>
2323
<block type="lha_time"></block>
24+
<block type="lha_date"></block>
2425
<block type="lha_log"></block>
2526
</category>
2627
<sep></sep>

extensions/web-scripts/web-scripts.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ define(['requirePath', './scripts.xml', './script-editor.xml'], function(require
7373
"name": "EVENT",
7474
"options": [
7575
[ "startup", "startup" ],
76-
[ "poll", "polling" ],
76+
[ "polling", "poll" ],
7777
[ "shutdown", "shutdown" ]
7878
]
7979
}],
@@ -316,6 +316,42 @@ define(['requirePath', './scripts.xml', './script-editor.xml'], function(require
316316
var code = "os.time()";
317317
return [code, Blockly.JavaScript.ORDER_MEMBER];
318318
};
319+
Blockly.Blocks['lha_date'] = {
320+
init: function() {
321+
this.jsonInit({
322+
"message0": "get date field %1 from %2",
323+
"args0": [{
324+
"type": "field_dropdown",
325+
"name": "FIELD",
326+
"options": [
327+
[ "yearweek (0-53)", "W" ],
328+
[ "weekday (0-6)", "w" ],
329+
[ "year", "Y" ],
330+
[ "month (1-12)", "m" ],
331+
[ "day", "d" ],
332+
[ "minutes", "M" ],
333+
[ "hours", "H" ],
334+
[ "seconds", "S" ]
335+
]
336+
}, {
337+
"type": "input_value",
338+
"name": "VALUE"
339+
}],
340+
"output": null,
341+
"colour": lhaStatementColor
342+
});
343+
}
344+
};
345+
Blockly.Lua['lha_date'] = function(block) {
346+
var field = block.getFieldValue('FIELD');
347+
var value = Blockly.Lua.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_NONE);
348+
var code = "os.date('%" + field + "', " + value + ")";
349+
var numRe = new RegExp('^[VwYmdMHS]$');
350+
if (numRe.test(field)) {
351+
code = "tonumber(" + code + ")";
352+
}
353+
return [code, Blockly.JavaScript.ORDER_MEMBER];
354+
};
319355
// Registers action buttons
320356
workspace.registerButtonCallback('refresh', function() {
321357
self.refresh().then(function() {

0 commit comments

Comments
 (0)