summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Hansen <mark@markhansen.co.nz>2010-02-15 01:11:59 +1300
committerRyan Dahl <ry@tinyclouds.org>2010-02-15 17:08:22 -0800
commit98e61db21619228e55453eeaab8bb59a3f8eb914 (patch)
tree68a78bc5db78ac277b1f16e0a9ecfdef0ae952c9
parent9c6263bff8b7c18b7f5ca1880102d05c5e0a2529 (diff)
downloadandroid-node-v8-98e61db21619228e55453eeaab8bb59a3f8eb914.tar.gz
android-node-v8-98e61db21619228e55453eeaab8bb59a3f8eb914.tar.bz2
android-node-v8-98e61db21619228e55453eeaab8bb59a3f8eb914.zip
sys.inspect(Date) now shows the date value
-rw-r--r--lib/sys.js10
-rw-r--r--test/mjsunit/test-sys.js10
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/sys.js b/lib/sys.js
index 581af38dfe..65badcdc05 100644
--- a/lib/sys.js
+++ b/lib/sys.js
@@ -59,6 +59,11 @@ exports.inspect = function (obj, showHidden) {
}
}
+ // Dates without properties can be shortcutted
+ if (value instanceof Date && keys.length === 0) {
+ return value.toUTCString();
+ }
+
var base, type, braces;
// Determine the object type
if (value instanceof Array) {
@@ -75,6 +80,11 @@ exports.inspect = function (obj, showHidden) {
} else {
base = "";
}
+
+ // Make dates with properties first say the date
+ if (value instanceof Date) {
+ base = ' ' + value.toUTCString();
+ }
seen.push(value);
diff --git a/test/mjsunit/test-sys.js b/test/mjsunit/test-sys.js
index 6ba2157e8e..648452b0da 100644
--- a/test/mjsunit/test-sys.js
+++ b/test/mjsunit/test-sys.js
@@ -10,6 +10,8 @@ assert.equal("[Function]", inspect(function() {}));
assert.equal('undefined', inspect(undefined));
assert.equal('null', inspect(null));
assert.equal('/foo(bar\\n)?/gi', inspect(/foo(bar\n)?/gi));
+assert.equal('Sun, 14 Feb 2010 11:48:40 GMT',
+ inspect(new Date("Sun, 14 Feb 2010 11:48:40 GMT")));
assert.equal("\"\\n\\u0001\"", inspect("\n\u0001"));
@@ -79,3 +81,11 @@ assert.equal(
"{ /123/gi\n \"aprop\": 42\n}",
inspect(value)
);
+
+// Dates with properties
+value = new Date("Sun, 14 Feb 2010 11:48:40 GMT");
+value.aprop = 42;
+assert.equal(
+ "{ Sun, 14 Feb 2010 11:48:40 GMT\n \"aprop\": 42\n}",
+ inspect(value)
+);