From 4b1fb7e03a48bad9136a2b76be81f709122aeb4c Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 8 Oct 2007 21:14:24 +0000 Subject: [PATCH] prototype: Date#toJSON now returns times in UTC for better compatibility with json.js. Closes #9332. --- CHANGELOG | 2 ++ src/base.js | 12 ++++++------ test/unit/base.html | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2883371..e560ac9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Date#toJSON now returns times in UTC for better compatibility with json.js. Closes #9332. [Tobie Langel] + * Ensure document._getElementsByXPath extends the elements it returns; fixes $$ not returning extended elements in Opera 9.2. Closes #8843. [jdalton] * Update Prototype.Browser.MobileSafari for iPod touch compatibility. [sam] diff --git a/src/base.js b/src/base.js index a543dc9..3be7c8e 100644 --- a/src/base.js +++ b/src/base.js @@ -197,12 +197,12 @@ Object.extend(Function.prototype, { Function.prototype.defer = Function.prototype.delay.curry(0.01); Date.prototype.toJSON = function() { - return '"' + this.getFullYear() + '-' + - (this.getMonth() + 1).toPaddedString(2) + '-' + - this.getDate().toPaddedString(2) + 'T' + - this.getHours().toPaddedString(2) + ':' + - this.getMinutes().toPaddedString(2) + ':' + - this.getSeconds().toPaddedString(2) + '"'; + return '"' + this.getUTCFullYear() + '-' + + (this.getUTCMonth() + 1).toPaddedString(2) + '-' + + this.getUTCDate().toPaddedString(2) + 'T' + + this.getUTCHours().toPaddedString(2) + ':' + + this.getUTCMinutes().toPaddedString(2) + ':' + + this.getUTCSeconds().toPaddedString(2) + 'Z"'; }; var Try = { diff --git a/test/unit/base.html b/test/unit/base.html index c48777b..53e68a2 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -331,7 +331,7 @@ }, testDateToJSON: function() {with(this) { - assertEqual('\"1969-12-31T19:00:00\"', new Date(1969, 11, 31, 19).toJSON()); + assertEqual('\"1970-01-01T00:00:00Z\"', new Date(Date.UTC(1970, 0, 1)).toJSON()); }}, testRegExpEscape: function() {with(this) {