From 93d67ed386bba4862ac00eb55dcf664300ce53c7 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 15 Jun 2015 18:49:24 -0700 Subject: Fix Error Handing in the DATE block For some reason the function wasnt properly catching errors and was instead rasing native JS errors. This fixes that bug, so the function will now report nothing when it doesnt know what to do. In addition, moving the variable `dateMap` inside the function reduces a global variable, which shouldnt affect anything other than keeping the code clean. :) --- threads.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/threads.js b/threads.js index 165ad0e..efe9ba4 100644 --- a/threads.js +++ b/threads.js @@ -2640,26 +2640,26 @@ Process.prototype.reportTimer = function () { }; // 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](); + // Map block options to built-in functions + dateMap = { + 'year' : 'getFullYear', + 'month' : 'getMonth', + 'date': 'getDate', + 'day of week' : 'getDay', + 'hour' : 'getHours', + 'minute' : 'getMinutes', + 'second' : 'getSeconds', + 'time in milliseconds' : 'getTime' + }; if (!dateMap[inputFn]) { return ''; } + var 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; -- cgit v1.3.1