@@ -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