OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 963 matching lines...) Loading... |
974 | 974 |
975 function PadInt(n, digits) { | 975 function PadInt(n, digits) { |
976 if (digits == 1) return n; | 976 if (digits == 1) return n; |
977 return n < MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n; | 977 return n < MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n; |
978 } | 978 } |
979 | 979 |
980 | 980 |
981 function DateToISOString() { | 981 function DateToISOString() { |
982 var t = DATE_VALUE(this); | 982 var t = DATE_VALUE(this); |
983 if (NUMBER_IS_NAN(t)) return kInvalidDate; | 983 if (NUMBER_IS_NAN(t)) return kInvalidDate; |
984 return this.getUTCFullYear() + | 984 var year = this.getUTCFullYear(); |
| 985 var year_string; |
| 986 if (year >= 0 && year <= 9999) { |
| 987 year_string = PadInt(year, 4); |
| 988 } else { |
| 989 if (year < 0) { |
| 990 year_string = "-" + PadInt(-year, 6); |
| 991 } else { |
| 992 year_string = "+" + PadInt(year, 6); |
| 993 } |
| 994 } |
| 995 return year_string + |
985 '-' + PadInt(this.getUTCMonth() + 1, 2) + | 996 '-' + PadInt(this.getUTCMonth() + 1, 2) + |
986 '-' + PadInt(this.getUTCDate(), 2) + | 997 '-' + PadInt(this.getUTCDate(), 2) + |
987 'T' + PadInt(this.getUTCHours(), 2) + | 998 'T' + PadInt(this.getUTCHours(), 2) + |
988 ':' + PadInt(this.getUTCMinutes(), 2) + | 999 ':' + PadInt(this.getUTCMinutes(), 2) + |
989 ':' + PadInt(this.getUTCSeconds(), 2) + | 1000 ':' + PadInt(this.getUTCSeconds(), 2) + |
990 '.' + PadInt(this.getUTCMilliseconds(), 3) + | 1001 '.' + PadInt(this.getUTCMilliseconds(), 3) + |
991 'Z'; | 1002 'Z'; |
992 } | 1003 } |
993 | 1004 |
994 | 1005 |
995 function DateToJSON(key) { | 1006 function DateToJSON(key) { |
996 var o = ToObject(this); | 1007 var o = ToObject(this); |
997 var tv = DefaultNumber(o); | 1008 var tv = DefaultNumber(o); |
998 if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) { | 1009 if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) { |
999 return null; | 1010 return null; |
1000 } | 1011 } |
1001 return o.toISOString(); | 1012 return o.toISOString(); |
1002 } | 1013 } |
1003 | 1014 |
1004 | 1015 |
1005 function ResetDateCache() { | 1016 function ResetDateCache() { |
1006 | 1017 |
1007 // Reset the local_time_offset: | 1018 // Reset the local_time_offset: |
1008 local_time_offset = %DateLocalTimeOffset(); | 1019 local_time_offset = %DateLocalTimeOffset(); |
1009 | 1020 |
(...skipping 84 matching lines...) Loading... |
1094 "toGMTString", DateToGMTString, | 1105 "toGMTString", DateToGMTString, |
1095 "toUTCString", DateToUTCString, | 1106 "toUTCString", DateToUTCString, |
1096 "getYear", DateGetYear, | 1107 "getYear", DateGetYear, |
1097 "setYear", DateSetYear, | 1108 "setYear", DateSetYear, |
1098 "toISOString", DateToISOString, | 1109 "toISOString", DateToISOString, |
1099 "toJSON", DateToJSON | 1110 "toJSON", DateToJSON |
1100 )); | 1111 )); |
1101 } | 1112 } |
1102 | 1113 |
1103 SetupDate(); | 1114 SetupDate(); |
OLD | NEW |