diff --git a/js/primitives/SensingPrims.js b/js/primitives/SensingPrims.js index 0529081..6ae31d5 100644 --- a/js/primitives/SensingPrims.js +++ b/js/primitives/SensingPrims.js @@ -29,6 +29,8 @@ SensingPrims.prototype.addPrimsTo = function(primTable) { primTable['distanceTo:'] = this.primDistanceTo; primTable['getAttribute:of:'] = this.primGetAttribute; + + primTable['timeAndDate'] = this.primTimeDate; } SensingPrims.prototype.primTouching = function(b) { @@ -206,6 +208,19 @@ SensingPrims.prototype.primGetAttribute = function(b) { return 0; } +SensingPrims.prototype.primTimeDate = function(b) { + var dt = interp.arg(b, 0); + var now = new Date(); + if (dt == 'year') return now.getFullYear(); + if (dt == 'month') return now.getMonth()+1; + if (dt == 'date') return now.getDate(); + if (dt == 'day of week') return now.getDay()+1; + if (dt == 'hour') return now.getHours(); + if (dt == 'minute') return now.getMinutes(); + if (dt == 'second') return now.getSeconds(); + return 0; +} + // Helpers SensingPrims.prototype.mouseOrSpritePosition = function(arg) { if (arg == "_mouse_") {