Revision: 3601
Author: [email protected]
Date: Thu Jan 14 00:55:15 2010
Log: Fix Date.prototype.toISOString for NaN dates and add milliseconds for
compatibility with Safari.

Review URL: http://codereview.chromium.org/543056
http://code.google.com/p/v8/source/detail?r=3601

Modified:
 /branches/bleeding_edge/src/date-delay.js

=======================================
--- /branches/bleeding_edge/src/date-delay.js   Thu Jan  7 23:49:07 2010
+++ /branches/bleeding_edge/src/date-delay.js   Thu Jan 14 00:55:15 2010
@@ -1048,16 +1048,19 @@
 }


-function PadInt(n) {
-  // Format integers to have at least two digits.
-  return n < 10 ? '0' + n : n;
+function PadInt(n, digits) {
+  if (digits == 1) return n;
+  return n < MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n;
 }


 function DateToISOString() {
-  return this.getUTCFullYear() + '-' + PadInt(this.getUTCMonth() + 1) +
-      '-' + PadInt(this.getUTCDate()) + 'T' + PadInt(this.getUTCHours()) +
- ':' + PadInt(this.getUTCMinutes()) + ':' + PadInt(this.getUTCSeconds()) +
+  var t = DATE_VALUE(this);
+  if (NUMBER_IS_NAN(t)) return kInvalidDate;
+  return this.getUTCFullYear() + '-' + PadInt(this.getUTCMonth() + 1, 2) +
+ '-' + PadInt(this.getUTCDate(), 2) + 'T' + PadInt(this.getUTCHours(), 2) + + ':' + PadInt(this.getUTCMinutes(), 2) + ':' + PadInt(this.getUTCSeconds(), 2) +
+      '.' + PadInt(this.getUTCMilliseconds(), 3) +
       'Z';
 }

-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to