From faa8b4fe2243b1a8ef5cc4342183f4880b728a3d Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Fri, 27 Dec 2013 18:49:56 -0800 Subject: Add a 'get current DATE' block with various options, add some translations to FR and DE --- threads.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'threads.js') diff --git a/threads.js b/threads.js index d1e57d3..13fcff3 100644 --- a/threads.js +++ b/threads.js @@ -2474,6 +2474,34 @@ Process.prototype.reportTimer = function () { return 0; }; +// Process Dates and times in Snap + +Process.prototype.reportDate = function (datefn) { + // Map block options to built-in functions + var dateMap = { 'Date' : 'toLocaleDateString', + 'Time' : 'toLocaleTimeString', + 'Month' : 'getMonthName', // return a name, not a number + 'Day of Week' : 'getDayName', // return a name, not a number + 'Day of Month': 'getDate', + 'Year' : 'getFullYear', + 'Hour' : 'getHours', + 'Minute' : 'getMinutes', + 'Second' : 'getSeconds', + 'Milliseconds' : 'getMilliseconds', + 'Time in Milliseconds' : 'getTime', + 'UTC Time' : 'toUTCString' }; + + if (!dateMap[datefn]) { + return ''; + } + + currDate = new Date(); + func = dateMap[datefn] + + return currDate[func](); + +} + // Process code mapping /* @@ -3068,3 +3096,33 @@ UpvarReference.prototype.toString = function () { UpvarReference.prototype.names = VariableFrame.prototype.names; UpvarReference.prototype.allNames = VariableFrame.prototype.allNames; UpvarReference.prototype.allNamesDict = VariableFrame.prototype.allNamesDict; + +// Date Utilities (for the 'reportDate' block) + +Date.prototype.getMonthName = function () { + mons = ['January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December']; + return localize(mons[this.getMonth()]); +} + +Date.prototype.getDayName = function () { + days = ['Sunday', + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday']; + return localize(days[this.getDay()]); +} + -- cgit v1.3.1 From 9f0f9dde37730dea46539c4c8971561a0a042354 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 28 Dec 2013 15:01:24 -0800 Subject: Add style tweaks per Nathan's comments. --- blocks.js | 24 ++++++++++++------------ objects.js | 5 ++--- threads.js | 37 +++++++++++++++++-------------------- 3 files changed, 31 insertions(+), 35 deletions(-) (limited to 'threads.js') diff --git a/blocks.js b/blocks.js index ed936d1..a1d80f5 100644 --- a/blocks.js +++ b/blocks.js @@ -817,21 +817,21 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { null, // text false, // non-numeric { - 'Date' : ['Date'], - 'Month' : ['Month'], - 'Day of Month' : ['Day of Month'], - 'Year' : ['Year'], - 'Day of Week' : ['Day of Week'], - 'Time' : ['Time'], - 'Hour' : ['Hour'], - 'Minute' : ['Minute'], - 'Second' : ['Second'], - 'Time in Milliseconds' : ['Time in Milliseconds'], - 'UTC Time' : ['UTC Time'], + 'date' : ['date'], + 'month' : ['month'], + 'year' : ['year'], + 'day of month' : ['day of month'], + 'day of week' : ['day of week'], + 'time' : ['time'], + 'hour' : ['hour'], + 'minute' : ['minute'], + 'second' : ['second'], + 'time in milliseconds' : ['time in milliseconds'], + 'UTC time' : ['UTC time'], }, true // read-only ); - part.setContents('Date') + part.setContents('date'); break; case '%delim': part = new InputSlotMorph( diff --git a/objects.js b/objects.js index a2caedd..46be53c 100644 --- a/objects.js +++ b/objects.js @@ -124,7 +124,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2013-December-27'; +modules.objects = '2013-December-28'; var SpriteMorph; var StageMorph; @@ -789,8 +789,7 @@ SpriteMorph.prototype.initBlocks = function () { reportDate: { type: 'reporter', category: 'sensing', - spec: 'get current %dates', - + spec: 'get current %dates' }, // Operators diff --git a/threads.js b/threads.js index 13fcff3..9192023 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2013-December-11'; +modules.threads = '2013-December-28'; var ThreadManager; var Process; @@ -2475,31 +2475,28 @@ Process.prototype.reportTimer = function () { }; // Process Dates and times in Snap +// Map block options to built-in functions +var dateMap = { + 'date' : 'toLocaleDateString', + 'time' : 'toLocaleTimeString', + 'month' : 'getMonthName', // return a name, not a number + 'year' : 'getFullYear', + 'day of week' : 'getDayName', // return a name, not a number + 'day of month': 'getDate', + 'hour' : 'getHours', + 'minute' : 'getMinutes', + 'second' : 'getSeconds', + 'milliseconds' : 'getMilliseconds', + 'time in milliseconds' : 'getTime', + 'UTC time' : 'toUTCString' }; Process.prototype.reportDate = function (datefn) { - // Map block options to built-in functions - var dateMap = { 'Date' : 'toLocaleDateString', - 'Time' : 'toLocaleTimeString', - 'Month' : 'getMonthName', // return a name, not a number - 'Day of Week' : 'getDayName', // return a name, not a number - 'Day of Month': 'getDate', - 'Year' : 'getFullYear', - 'Hour' : 'getHours', - 'Minute' : 'getMinutes', - 'Second' : 'getSeconds', - 'Milliseconds' : 'getMilliseconds', - 'Time in Milliseconds' : 'getTime', - 'UTC Time' : 'toUTCString' }; - - if (!dateMap[datefn]) { - return ''; - } + if (!dateMap[datefn]) { return ''; } currDate = new Date(); - func = dateMap[datefn] + func = dateMap[datefn]; return currDate[func](); - } // Process code mapping -- cgit v1.3.1 From ede60eec562d93411eb26462e789b8414d5455f1 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Wed, 22 Jan 2014 20:05:46 -0800 Subject: date block work --- threads.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 9192023..735f17b 100644 --- a/threads.js +++ b/threads.js @@ -2479,16 +2479,14 @@ Process.prototype.reportTimer = function () { var dateMap = { 'date' : 'toLocaleDateString', 'time' : 'toLocaleTimeString', - 'month' : 'getMonthName', // return a name, not a number 'year' : 'getFullYear', + 'month' : 'getMonthName', // return a name, not a number + 'date': 'getDate', 'day of week' : 'getDayName', // return a name, not a number - 'day of month': 'getDate', 'hour' : 'getHours', 'minute' : 'getMinutes', 'second' : 'getSeconds', - 'milliseconds' : 'getMilliseconds', - 'time in milliseconds' : 'getTime', - 'UTC time' : 'toUTCString' }; + 'time in milliseconds' : 'getTime' }; Process.prototype.reportDate = function (datefn) { if (!dateMap[datefn]) { return ''; } -- cgit v1.3.1 From ccce2c9ac7167a5efa4573a87f6e149ed9cc2c87 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sun, 26 Jan 2014 04:25:36 -0800 Subject: adjust block to no longer use strings, and remove unneeded code --- lang-de.js | 44 +++----------------------------------------- lang-fr.js | 43 ++----------------------------------------- threads.js | 50 ++++++++++++-------------------------------------- 3 files changed, 17 insertions(+), 120 deletions(-) (limited to 'threads.js') diff --git a/lang-de.js b/lang-de.js index 7bf847c..1ac5f10 100644 --- a/lang-de.js +++ b/lang-de.js @@ -1248,45 +1248,7 @@ SnapTranslator.dict.de = { 'beliebiges', // Date reporter dropdowns - 'Month': - 'Monat', - // Months of the Year - 'January': - 'Januar', - 'February': - 'Februar', - 'March': - 'März', - 'April': - 'April', - 'May': - 'Mai', - 'June': - 'Juni', - 'July': - 'Juli', - 'August': - 'August', - 'September': - 'September', - 'October': - 'Oktober', - 'November': - 'November', - 'December': - 'Dezember', - 'Sunday': - 'Sonntag', - 'Monday': - 'Montag', - 'Tuesday': - 'Dienstag', - 'Wednesday': - 'Mittwoch', - 'Thursday': - 'Donnerstag', - 'Friday': - 'Freitag', - 'Saturday': - 'Samstag', + 'month': + 'monat', + }; diff --git a/lang-fr.js b/lang-fr.js index 4402e4c..6655909 100644 --- a/lang-fr.js +++ b/lang-fr.js @@ -1163,46 +1163,7 @@ SnapTranslator.dict.fr = { 'n\u0027importe quel', // Date reporter dropdowns - 'Month': - 'mois', - // Months of the Year - 'January': - 'janvier', - 'February': - 'février', - 'March': - 'mars', - 'April': - 'avril', - 'May': - 'mai', - 'June': - 'juin', - 'July': - 'juillet', - 'August': - 'août', - 'September': - 'septembre', - 'October': - 'octobre', - 'November': - 'novembre', - 'December': - 'decembre', - 'Sunday': - 'dimanche', - 'Monday': - 'lundi', - 'Tuesday': - 'mardi', - 'Wednesday': - 'mercredi', - 'Thursday': - 'jedui', - 'Friday': - 'vendredi', - 'Saturday': - 'samedi', + 'month': + 'mois' }; diff --git a/threads.js b/threads.js index 735f17b..0647040 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2013-December-28'; +modules.threads = '2014-January-26'; 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(); } @@ -2477,12 +2477,10 @@ Process.prototype.reportTimer = function () { // Process Dates and times in Snap // Map block options to built-in functions var dateMap = { - 'date' : 'toLocaleDateString', - 'time' : 'toLocaleTimeString', 'year' : 'getFullYear', - 'month' : 'getMonthName', // return a name, not a number + 'month' : 'getMonth', 'date': 'getDate', - 'day of week' : 'getDayName', // return a name, not a number + 'day of week' : 'getDay', 'hour' : 'getHours', 'minute' : 'getMinutes', 'second' : 'getSeconds', @@ -2493,8 +2491,14 @@ Process.prototype.reportDate = function (datefn) { currDate = new Date(); func = dateMap[datefn]; - - return currDate[func](); + result = currDate[func](); + + // Show months as 1-12 and days as 1-7 + if (datefn === 'month' || datefn === 'day of week') { + result += 1; + } + + return result; } // Process code mapping @@ -3091,33 +3095,3 @@ UpvarReference.prototype.toString = function () { UpvarReference.prototype.names = VariableFrame.prototype.names; UpvarReference.prototype.allNames = VariableFrame.prototype.allNames; UpvarReference.prototype.allNamesDict = VariableFrame.prototype.allNamesDict; - -// Date Utilities (for the 'reportDate' block) - -Date.prototype.getMonthName = function () { - mons = ['January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December']; - return localize(mons[this.getMonth()]); -} - -Date.prototype.getDayName = function () { - days = ['Sunday', - 'Monday', - 'Tuesday', - 'Wednesday', - 'Thursday', - 'Friday', - 'Saturday']; - return localize(days[this.getDay()]); -} - -- cgit v1.3.1 From 5fd102c8a98d18d24d9739cb961ec8dd2ac8935e Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Fri, 7 Feb 2014 15:16:14 -0800 Subject: use inputOption for dateblock update file date --- threads.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 7b46f70..4d3cbce 100644 --- a/threads.js +++ b/threads.js @@ -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; @@ -2549,14 +2549,16 @@ var dateMap = { 'time in milliseconds' : 'getTime' }; Process.prototype.reportDate = function (datefn) { - if (!dateMap[datefn]) { return ''; } + inputFn = this.inputOption(datefn); + + if (!dateMap[inputFn]) { return ''; } currDate = new Date(); - func = dateMap[datefn]; + func = dateMap[inputFn]; result = currDate[func](); // Show months as 1-12 and days as 1-7 - if (datefn === 'month' || datefn === 'day of week') { + if (inputFn === 'month' || inputFn === 'day of week') { result += 1; } -- cgit v1.3.1 From 407dbda43fb3e5e5e1af94417c585dd9004d2e6a Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 10 Feb 2014 10:51:22 -0800 Subject: jslint style fixes --- threads.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 4d3cbce..77632d0 100644 --- a/threads.js +++ b/threads.js @@ -2546,24 +2546,24 @@ var dateMap = { 'hour' : 'getHours', 'minute' : 'getMinutes', 'second' : 'getSeconds', - 'time in milliseconds' : 'getTime' }; + 'time in milliseconds' : 'getTime' +}; Process.prototype.reportDate = function (datefn) { - inputFn = this.inputOption(datefn); + var inputFn = this.inputOption(datefn), + currDate = new Date(), + func = dateMap[inputFn], + result = currDate[func](); if (!dateMap[inputFn]) { return ''; } - currDate = new Date(); - func = dateMap[inputFn]; - result = currDate[func](); - // Show months as 1-12 and days as 1-7 if (inputFn === 'month' || inputFn === 'day of week') { result += 1; } return result; -} +}; // Process code mapping -- cgit v1.3.1