diff options
| author | Jens Mönig <jens@moenig.org> | 2014-02-11 17:55:19 +0100 |
|---|---|---|
| committer | Jens Mönig <jens@moenig.org> | 2014-02-11 17:55:19 +0100 |
| commit | 3e7891b5a637196130393d51ba6ff2747926995f (patch) | |
| tree | 3504d46dffac1104e1fcdac9ab2033167454f6b2 | |
| parent | 0e0146a0d805389fed1064a5a94db43b1f0e4d3b (diff) | |
| parent | 407dbda43fb3e5e5e1af94417c585dd9004d2e6a (diff) | |
| download | snap-byow-3e7891b5a637196130393d51ba6ff2747926995f.tar.gz snap-byow-3e7891b5a637196130393d51ba6ff2747926995f.zip | |
Merge pull request #288 from cycomachead/dateblock
Create a "Date" Block for Snap
| -rw-r--r-- | blocks.js | 24 | ||||
| -rw-r--r-- | objects.js | 11 | ||||
| -rw-r--r-- | threads.js | 33 |
3 files changed, 62 insertions, 6 deletions
@@ -155,7 +155,8 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2014-January-09'; +modules.blocks = '2014-February-04'; + var SyntaxElementMorph; var BlockMorph; @@ -812,6 +813,24 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { true // read-only ); break; + case '%dates': + part = new InputSlotMorph( + null, // text + false, // non-numeric + { + 'year' : ['year'], + 'month' : ['month'], + 'date' : ['date'], + 'day of week' : ['day of week'], + 'hour' : ['hour'], + 'minute' : ['minute'], + 'second' : ['second'], + 'time in milliseconds' : ['time in milliseconds'], + }, + true // read-only + ); + part.setContents(['date']); + break; case '%delim': part = new InputSlotMorph( null, // text @@ -1192,7 +1211,6 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { ); break; - // symbols: case '%turtle': @@ -6174,7 +6192,7 @@ CSlotMorph.prototype.drawBottomEdge = function (context) { I am an editable text input slot. I can be either rectangular or rounded, and can have an optional drop-down menu. If I'm set to read-only I must have a drop-down menu and will assume a darker - shade of my parent's color. + shade of my parent's color. my most important public attributes and accessors are: @@ -804,6 +804,11 @@ SpriteMorph.prototype.initBlocks = function () { category: 'sensing', spec: 'set turbo mode to %b' }, + reportDate: { + type: 'reporter', + category: 'sensing', + spec: 'current %dates' + }, // Operators reifyScript: { @@ -1740,6 +1745,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportIsFastTracking')); blocks.push(block('doSetFastTracking')); + blocks.push('-'); + blocks.push(block('reportDate')); // for debugging: /////////////// @@ -4448,6 +4455,8 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportIsFastTracking')); blocks.push(block('doSetFastTracking')); + blocks.push('-'); + blocks.push(block('reportDate')); // for debugging: /////////////// @@ -5197,7 +5206,7 @@ Costume.prototype.shrinkWrap = function () { }; Costume.prototype.boundingBox = function () { - // answer the rectangle surrounding my contents' non-transparent pixels + // answer the rectangle surrounding my contents' non-transparent pixels var row, col, pic = this.contents, @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2014-Feb-03'; +modules.threads = '2014-Feb-10'; var ThreadManager; var Process; @@ -111,7 +111,7 @@ function snapEquals(a, b) { y = b; } - // handle text comparision text-insensitive. + // handle text comparision case-insensitive. if (isString(x) && isString(y)) { return x.toLowerCase() === y.toLowerCase(); } @@ -2536,6 +2536,35 @@ Process.prototype.reportTimer = function () { return 0; }; +// Process Dates and times in Snap +// Map block options to built-in functions +var dateMap = { + 'year' : 'getFullYear', + 'month' : 'getMonth', + 'date': 'getDate', + 'day of week' : 'getDay', + 'hour' : 'getHours', + 'minute' : 'getMinutes', + 'second' : 'getSeconds', + 'time in milliseconds' : 'getTime' +}; + +Process.prototype.reportDate = function (datefn) { + var inputFn = this.inputOption(datefn), + currDate = new Date(), + func = dateMap[inputFn], + result = currDate[func](); + + if (!dateMap[inputFn]) { return ''; } + + // Show months as 1-12 and days as 1-7 + if (inputFn === 'month' || inputFn === 'day of week') { + result += 1; + } + + return result; +}; + // Process code mapping /* |
