From 7999203ae067fb0dc97aca536ccc346f7c7d5069 Mon Sep 17 00:00:00 2001 From: bkuker Date: Fri, 9 Jan 2015 10:26:20 -0500 Subject: [PATCH 1/6] Show formatted date values as comments. -Seconds & Millis from Jan 1 2000 to Jan 1 2038 -Dates resulting from JSON.stringify({'now': new Date()}) --- WebContent/jsonview.css | 4 ++++ WebContent/workerFormatter.js | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/WebContent/jsonview.css b/WebContent/jsonview.css index 61e1fe9..6f6f1e5 100644 --- a/WebContent/jsonview.css +++ b/WebContent/jsonview.css @@ -23,6 +23,10 @@ body { color: green; } +.type-date { + color: gray; +} + .callback-function { color: gray; } diff --git a/WebContent/workerFormatter.js b/WebContent/workerFormatter.js index 1850bdd..c2db8c7 100644 --- a/WebContent/workerFormatter.js +++ b/WebContent/workerFormatter.js @@ -12,8 +12,22 @@ function decorateWithSpan(value, className) { return '' + htmlEncode(value) + ''; } +function maybeDate(value) { + var valueType = typeof value; + if (valueType == "number") { + if (value > 946684800 && value < 2145916800) + return new Date(value * 1000); + else if (value > 946684800000 && value < 2145916800000) + return new Date(value); + } else if (valueType == "string") { + if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(value)) + return new Date(value); + } + return false; +} + function valueToHTML(value) { - var valueType = typeof value, output = ""; + var valueType = typeof value, output = "", asDate = maybeDate(value); if (value == null) output += decorateWithSpan("null", "type-null"); else if (value && value.constructor == Array) @@ -30,6 +44,9 @@ function valueToHTML(value) { else if (valueType == "boolean") output += decorateWithSpan(value, "type-boolean"); + if ( asDate ){ + output += ' /* [' + asDate.toUTCString() + '], [' + asDate.toLocaleString() + '] */'; + } return output; } From e8753f745cc72778b1afa5059772fcd739b965c8 Mon Sep 17 00:00:00 2001 From: bkuker Date: Thu, 16 Apr 2015 10:01:24 -0400 Subject: [PATCH 2/6] Format dates & links in Keys, and numeric dates in Strings --- WebContent/workerFormatter.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/WebContent/workerFormatter.js b/WebContent/workerFormatter.js index c2db8c7..ac77569 100644 --- a/WebContent/workerFormatter.js +++ b/WebContent/workerFormatter.js @@ -14,6 +14,10 @@ function decorateWithSpan(value, className) { function maybeDate(value) { var valueType = typeof value; + if (valueType == "string" && !isNaN(parseInt(value)) && isFinite(value) ){ + value = parseInt(value); + valueType = "number"; + } if (valueType == "number") { if (value > 946684800 && value < 2145916800) return new Date(value * 1000); @@ -66,13 +70,28 @@ function arrayToHTML(json) { return output; } +function keyToHTML(value) { + var valueType = typeof value, output = "", asDate = maybeDate(value); + if (valueType == "string"){ + if (/^(http|https):\/\/[^\s]+$/.test(value)) + output += '' + htmlEncode(value) + ''; + else + output += htmlEncode(value); + } + if (asDate) { + output += ' /* [' + asDate.toUTCString() + '], [' + asDate.toLocaleString() + + '] */'; + } + return output; +} + function objectToHTML(json) { var i, key, length, keys = Object.keys(json), output = '
{