diff options
| author | Michael Ball <cycomachead@gmail.com> | 2013-12-27 18:49:56 -0800 |
|---|---|---|
| committer | Michael Ball <cycomachead@gmail.com> | 2013-12-27 18:49:56 -0800 |
| commit | faa8b4fe2243b1a8ef5cc4342183f4880b728a3d (patch) | |
| tree | f158b1b8c6a3b7c0923ba0660f1fca4ba4c55635 /threads.js | |
| parent | e9020b4ed3f7190dc78e622fbe3b2665e227c30f (diff) | |
| download | snap-yow-faa8b4fe2243b1a8ef5cc4342183f4880b728a3d.tar.gz snap-yow-faa8b4fe2243b1a8ef5cc4342183f4880b728a3d.zip | |
Add a 'get current DATE' block with various options, add some translations to FR and DE
Diffstat (limited to 'threads.js')
| -rw-r--r-- | threads.js | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -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()]); +} + |
