Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: src/date-delay.js

Issue 93066: Built-in JSON support (Closed)
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/date-delay.js
diff --git a/src/date-delay.js b/src/date-delay.js
index 2421e5baecc94c2602e9d6fafd4e500da2de0d1b..dbb9c2c044d4f0e20efb205c5a75619dbd724d7c 100644
--- a/src/date-delay.js
+++ b/src/date-delay.js
@@ -985,6 +985,25 @@ function DateToGMTString() {
}
+function PadInt(n) {
+ // Format integers to have at least two digits.
+ return n < 10 ? '0' + n : n;
+}
+
+
+function DateToISOString() {
+ return this.getUTCFullYear() + '-' + PadInt(this.getUTCMonth() + 1) +
+ '-' + PadInt(this.getUTCDate()) + 'T' + PadInt(this.getUTCHours()) +
+ ':' + PadInt(this.getUTCMinutes()) + ':' + PadInt(this.getUTCSeconds()) +
+ 'Z';
+}
+
+
+function DateToJSON(key) {
+ return CheckJSONPrimitive(this.toISOString());
+}
+
+
// -------------------------------------------------------------------
function SetupDate() {
@@ -1044,7 +1063,9 @@ function SetupDate() {
"toGMTString", DateToGMTString,
"toUTCString", DateToUTCString,
"getYear", DateGetYear,
- "setYear", DateSetYear
+ "setYear", DateSetYear,
+ "toISOString", DateToISOString,
+ "toJSON", DateToJSON
));
}

Powered by Google App Engine
This is Rietveld 408576698