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

Side by Side Diff: third_party/WebKit/Source/wtf/DateMath.cpp

Issue 2265443002: Fix an overflow in valueAsDate setter of temporal input types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: accept null Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved. 4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * Copyright (C) 2007-2009 Torch Mobile, Inc. 5 * Copyright (C) 2007-2009 Torch Mobile, Inc.
6 * Copyright (C) 2010 &yet, LLC. (nate@andyet.net) 6 * Copyright (C) 2010 &yet, LLC. (nate@andyet.net)
7 * 7 *
8 * The Original Code is Mozilla Communicator client code, released 8 * The Original Code is Mozilla Communicator client code, released
9 * March 31, 1998. 9 * March 31, 1998.
10 * 10 *
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 #endif 92 #endif
93 93
94 namespace WTF { 94 namespace WTF {
95 95
96 /* Constants */ 96 /* Constants */
97 97
98 static const double hoursPerDay = 24.0; 98 static const double hoursPerDay = 24.0;
99 static const double secondsPerDay = 24.0 * 60.0 * 60.0; 99 static const double secondsPerDay = 24.0 * 60.0 * 60.0;
100 100
101 static const double maxUnixTime = 2145859200.0; // 12/31/2037 101 static const double maxUnixTime = 2145859200.0; // 12/31/2037
102 static const double kMinimumECMADateInMs = -8640000000000000.0;
103 static const double kMaximumECMADateInMs = 8640000000000000.0;
102 104
103 // Day of year for the first day of each month, where index 0 is January, and da y 0 is January 1. 105 // Day of year for the first day of each month, where index 0 is January, and da y 0 is January 1.
104 // First for non-leap years, then for leap years. 106 // First for non-leap years, then for leap years.
105 static const int firstDayOfMonth[2][12] = { 107 static const int firstDayOfMonth[2][12] = {
106 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, 108 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
107 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335} 109 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
108 }; 110 };
109 111
110 static inline void getLocalTime(const time_t* localTime, struct tm* localTM) 112 static inline void getLocalTime(const time_t* localTime, struct tm* localTM)
111 { 113 {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 static void appendTwoDigitNumber(StringBuilder& builder, int number) 161 static void appendTwoDigitNumber(StringBuilder& builder, int number)
160 { 162 {
161 ASSERT(number >= 0 && number < 100); 163 ASSERT(number >= 0 && number < 100);
162 if (number <= 9) 164 if (number <= 9)
163 builder.append('0'); 165 builder.append('0');
164 builder.appendNumber(number); 166 builder.appendNumber(number);
165 } 167 }
166 168
167 int msToYear(double ms) 169 int msToYear(double ms)
168 { 170 {
171 DCHECK(std::isfinite(ms));
172 DCHECK_GE(ms, kMinimumECMADateInMs);
173 DCHECK_LE(ms, kMaximumECMADateInMs);
169 int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970); 174 int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970);
170 double msFromApproxYearTo1970 = msPerDay * daysFrom1970ToYear(approxYear); 175 double msFromApproxYearTo1970 = msPerDay * daysFrom1970ToYear(approxYear);
171 if (msFromApproxYearTo1970 > ms) 176 if (msFromApproxYearTo1970 > ms)
172 return approxYear - 1; 177 return approxYear - 1;
173 if (msFromApproxYearTo1970 + msPerDay * daysInYear(approxYear) <= ms) 178 if (msFromApproxYearTo1970 + msPerDay * daysInYear(approxYear) <= ms)
174 return approxYear + 1; 179 return approxYear + 1;
175 return approxYear; 180 return approxYear;
176 } 181 }
177 182
178 int dayInYear(double ms, int year) 183 int dayInYear(double ms, int year)
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 } 829 }
825 830
826 double convertToLocalTime(double ms) 831 double convertToLocalTime(double ms)
827 { 832 {
828 double utcOffset = calculateUTCOffset(); 833 double utcOffset = calculateUTCOffset();
829 double dstOffset = calculateDSTOffset(ms, utcOffset); 834 double dstOffset = calculateDSTOffset(ms, utcOffset);
830 return (ms + utcOffset + dstOffset); 835 return (ms + utcOffset + dstOffset);
831 } 836 }
832 837
833 } // namespace WTF 838 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698