| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 + FLOOR((year-1601)/400); | 74 + FLOOR((year-1601)/400); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 function TimeFromYear(year) { | 78 function TimeFromYear(year) { |
| 79 return msPerDay * DayFromYear(year); | 79 return msPerDay * DayFromYear(year); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 function InLeapYear(time) { | 83 function InLeapYear(time) { |
| 84 return DaysInYear(YearFromTime(time)) == 366 ? 1 : 0; | 84 return DaysInYear(YearFromTime(time)) - 365; // Returns 1 or 0. |
| 85 } | |
| 86 | |
| 87 | |
| 88 function DayWithinYear(time) { | |
| 89 return DAY(time) - DayFromYear(YearFromTime(time)); | |
| 90 } | 85 } |
| 91 | 86 |
| 92 | 87 |
| 93 // ECMA 262 - 15.9.1.9 | 88 // ECMA 262 - 15.9.1.9 |
| 94 function EquivalentYear(year) { | 89 function EquivalentYear(year) { |
| 95 // Returns an equivalent year in the range [2008-2035] matching | 90 // Returns an equivalent year in the range [2008-2035] matching |
| 96 // - leap year. | 91 // - leap year. |
| 97 // - week day of first day. | 92 // - week day of first day. |
| 98 var time = TimeFromYear(year); | 93 var time = TimeFromYear(year); |
| 99 var recent_year = (InLeapYear(time) == 0 ? 1967 : 1956) + | 94 var recent_year = (InLeapYear(time) == 0 ? 1967 : 1956) + |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 function DateToTimeString() { | 593 function DateToTimeString() { |
| 599 var t = DATE_VALUE(this); | 594 var t = DATE_VALUE(this); |
| 600 if (NUMBER_IS_NAN(t)) return kInvalidDate; | 595 if (NUMBER_IS_NAN(t)) return kInvalidDate; |
| 601 var time_zone_string = LocalTimezoneString(t); // May update local offset. | 596 var time_zone_string = LocalTimezoneString(t); // May update local offset. |
| 602 return TimeString(LocalTimeNoCheck(t)) + time_zone_string; | 597 return TimeString(LocalTimeNoCheck(t)) + time_zone_string; |
| 603 } | 598 } |
| 604 | 599 |
| 605 | 600 |
| 606 // ECMA 262 - 15.9.5.5 | 601 // ECMA 262 - 15.9.5.5 |
| 607 function DateToLocaleString() { | 602 function DateToLocaleString() { |
| 608 return DateToString.call(this); | 603 return %_CallFunction(this, DateToString); |
| 609 } | 604 } |
| 610 | 605 |
| 611 | 606 |
| 612 // ECMA 262 - 15.9.5.6 | 607 // ECMA 262 - 15.9.5.6 |
| 613 function DateToLocaleDateString() { | 608 function DateToLocaleDateString() { |
| 614 var t = DATE_VALUE(this); | 609 var t = DATE_VALUE(this); |
| 615 if (NUMBER_IS_NAN(t)) return kInvalidDate; | 610 if (NUMBER_IS_NAN(t)) return kInvalidDate; |
| 616 return LongDateString(LocalTimeNoCheck(t)); | 611 return LongDateString(LocalTimeNoCheck(t)); |
| 617 } | 612 } |
| 618 | 613 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 | 961 |
| 967 | 962 |
| 968 // ECMA 262 - B.2.6 | 963 // ECMA 262 - B.2.6 |
| 969 // | 964 // |
| 970 // Notice that this does not follow ECMA 262 completely. ECMA 262 | 965 // Notice that this does not follow ECMA 262 completely. ECMA 262 |
| 971 // says that toGMTString should be the same Function object as | 966 // says that toGMTString should be the same Function object as |
| 972 // toUTCString. JSC does not do this, so for compatibility we do not | 967 // toUTCString. JSC does not do this, so for compatibility we do not |
| 973 // do that either. Instead, we create a new function whose name | 968 // do that either. Instead, we create a new function whose name |
| 974 // property will return toGMTString. | 969 // property will return toGMTString. |
| 975 function DateToGMTString() { | 970 function DateToGMTString() { |
| 976 return DateToUTCString.call(this); | 971 return %_CallFunction(this, DateToUTCString); |
| 977 } | 972 } |
| 978 | 973 |
| 979 | 974 |
| 980 function PadInt(n, digits) { | 975 function PadInt(n, digits) { |
| 981 if (digits == 1) return n; | 976 if (digits == 1) return n; |
| 982 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; |
| 983 } | 978 } |
| 984 | 979 |
| 985 | 980 |
| 986 function DateToISOString() { | 981 function DateToISOString() { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 "toGMTString", DateToGMTString, | 1094 "toGMTString", DateToGMTString, |
| 1100 "toUTCString", DateToUTCString, | 1095 "toUTCString", DateToUTCString, |
| 1101 "getYear", DateGetYear, | 1096 "getYear", DateGetYear, |
| 1102 "setYear", DateSetYear, | 1097 "setYear", DateSetYear, |
| 1103 "toISOString", DateToISOString, | 1098 "toISOString", DateToISOString, |
| 1104 "toJSON", DateToJSON | 1099 "toJSON", DateToJSON |
| 1105 )); | 1100 )); |
| 1106 } | 1101 } |
| 1107 | 1102 |
| 1108 SetupDate(); | 1103 SetupDate(); |
| OLD | NEW |