Debian Codegraph @

src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * Copyright (C) 2007-2009 Torch Mobile, Inc.
6 *
7 * The Original Code is Mozilla Communicator client code, released
8 * March 31, 1998.
9 *
10 * The Initial Developer of the Original Code is
11 * Netscape Communications Corporation.
12 * Portions created by the Initial Developer are Copyright (C) 1998
13 * the Initial Developer. All Rights Reserved.
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 *
29 * Alternatively, the contents of this file may be used under the terms
30 * of either the Mozilla Public License Version 1.1, found at
31 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
32 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
33 * (the "GPL"), in which case the provisions of the MPL or the GPL are
34 * applicable instead of those above. If you wish to allow use of your
35 * version of this file only under the terms of one of those two
36 * licenses (the MPL or the GPL) and not to allow others to use your
37 * version of this file under the LGPL, indicate your decision by
38 * deletingthe provisions above and replace them with the notice and
39 * other provisions required by the MPL or the GPL, as the case may be.
40 * If you do not delete the provisions above, a recipient may use your
41 * version of this file under any of the LGPL, the MPL or the GPL.
42
43 * Copyright 2006-2008 the V8 project authors. All rights reserved.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions are
46 * met:
47 *
48 * * Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * * Redistributions in binary form must reproduce the above
51 * copyright notice, this list of conditions and the following
52 * disclaimer in the documentation and/or other materials provided
53 * with the distribution.
54 * * Neither the name of Google Inc. nor the names of its
55 * contributors may be used to endorse or promote products derived
56 * from this software without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
59 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
60 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
61 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
62 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
63 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
64 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
68 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 */
70
71 #include "config.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/config.h`/
72 #include "DateMath.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.h`/
73
74 #include "Assertions.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h`/
75 #include "ASCIICType.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/ASCIICType.h`/
76 #include "CurrentTime.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/CurrentTime.h`/
77 #include "StringExtras.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/StringExtras.h`/
78
79 #include <algorithm>
80 #include <limits.h>
81 #include <limits>
82 #include <stdint.h>
83 #include <time.h>
84
85
86 #if HAVEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:46:9`!(ERRNO_H)
87 #include <errno.h>
88 #endif
89
90 #if OScxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:49:9`!(WINCE)
91 extern "C" size_t strftime(char * const s, const size_t maxsize, const char * const format, const struct tm * const t);
92 extern "C" struct tm * localtime(const time_t *timer);
93 #endif
94
95 #if HAVEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:46:9`!(SYS_TIME_H)
96 #include <sys/time.h>
97 #endif
98
99 #if HAVEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:46:9`!(SYS_TIMEB_H)
100 #include <sys/timeb.h>
101 #endif
102
103 #if USEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:55:9`!(JSC)
104 #include "CallFrame.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/CallFrame.h`/
105 #endif
106
107 #include "MathExtras.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h`/
108
109 #define NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`! std::numeric_limits<double>::quiet_NaN()
110
111 using namespace WTFcxx . . $ `<built-in>:467:9`!;
112
113 namespace WTFcxx . . $ `<built-in>:467:9`! {
114
115 /* Constants */
116
117 static const double minutesPerDaycxx . . $ QTWTF/minutesPerDay. = 24.0 * 60.0;
118 static const double secondsPerDaycxx . . $ QTWTF/secondsPerDay. = 24.0 * 60.0 * 60.0;
119 static const double secondsPerYearcxx . . $ QTWTF/secondsPerYear. = 24.0 * 60.0 * 60.0 * 365.0;
120
121 static const double usecPerSeccxx . . $ QTWTF/usecPerSec. = 1000000.0;
122
123 static const double maxUnixTimecxx . . $ QTWTF/maxUnixTime. = 2145859200.0; // 12/31/2037
124 // ECMAScript asks not to support for a date of which total
125 // millisecond value is larger than the following value.
126 // See 15.9.1.14 of ECMA-262 5th edition.
127 static const double maxECMAScriptTimecxx . . $ QTWTF/maxECMAScriptTime. = 8.64E15;
128
129 // Day of year for the first day of each month, where index 0 is January, and day 0 is January 1.
130 // First for non-leap years, then for leap years.
131 static const int firstDayOfMonthcxx . . $ QTWTF/firstDayOfMonth.[2][12] = {
132 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
133 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
134 };
135
136 static inline bool isLeapYearcxx . . $ QTWTF/isLeapYear(83c267b20bac841a).(int year)
137 {
138 if (year % 4 != 0)
139 return false;
140 if (year % 400 == 0)
141 return true;
142 if (year % 100 == 0)
143 return false;
144 return true;
145 }
146
147 static inline int daysInYearcxx . . $ QTWTF/daysInYear(7864480464b09eea).(int year)
148 {
149 return 365 + isLeapYearcxx . . $ QTWTF/isLeapYear(83c267b20bac841a).(year);
150 }
151
152 static inline double daysFrom1970ToYearcxx . . $ QTWTF/daysFrom1970ToYear(4badf5dbac1308a7).(int year)
153 {
154 // The Gregorian Calendar rules for leap years:
155 // Every fourth year is a leap year. 2004, 2008, and 2012 are leap years.
156 // However, every hundredth year is not a leap year. 1900 and 2100 are not leap years.
157 // Every four hundred years, there's a leap year after all. 2000 and 2400 are leap years.
158
159 static const int leapDaysBefore1971By4Rule = 1970 / 4;
160 static const int excludedLeapDaysBefore1971By100Rule = 1970 / 100;
161 static const int leapDaysBefore1971By400Rule = 1970 / 400;
162
163 const double yearMinusOne = year - 1;
164 const double yearsToAddBy4Rule = floorcxx . . $ floor(447c67c6676f75c3).(yearMinusOne / 4.0) - leapDaysBefore1971By4Rule;
165 const double yearsToExcludeBy100Rule = floorcxx . . $ floor(447c67c6676f75c3).(yearMinusOne / 100.0) - excludedLeapDaysBefore1971By100Rule;
166 const double yearsToAddBy400Rule = floorcxx . . $ floor(447c67c6676f75c3).(yearMinusOne / 400.0) - leapDaysBefore1971By400Rule;
167
168 return 365.0 * (year - 1970) + yearsToAddBy4Rule - yearsToExcludeBy100Rule + yearsToAddBy400Rule;
169 }
170
171 static inline double msToDayscxx . . $ QTWTF/msToDays(447c67c6676f75c3).(double ms)
172 {
173 return floorcxx . . $ floor(447c67c6676f75c3).(ms / msPerDaycxx . . $ QTWTF/msPerDay.);
174 }
175
176 int msToYearcxx . . $ QTWTF/msToYear(620b9ac44d2573a6).(double ms)
177 {
178 int approxYear = static_cast<int>(floorcxx . . $ floor(447c67c6676f75c3).(ms / (msPerDaycxx . . $ QTWTF/msPerDay. * 365.2425)) + 1970);
179 double msFromApproxYearTo1970 = msPerDaycxx . . $ QTWTF/msPerDay. * daysFrom1970ToYearcxx . . $ QTWTF/daysFrom1970ToYear(4badf5dbac1308a7).(approxYear);
180 if (msFromApproxYearTo1970 > ms)
181 return approxYear - 1;
182 if (msFromApproxYearTo1970 + msPerDaycxx . . $ QTWTF/msPerDay. * daysInYearcxx . . $ QTWTF/daysInYear(7864480464b09eea).(approxYear) <= ms)
183 return approxYear + 1;
184 return approxYear;
185 }
186
187 int dayInYearcxx . . $ QTWTF/dayInYear(73c075bbbf02e8eb).(double ms, int year)
188 {
189 return static_cast<int>(msToDayscxx . . $ QTWTF/msToDays(447c67c6676f75c3).(ms) - daysFrom1970ToYearcxx . . $ QTWTF/daysFrom1970ToYear(4badf5dbac1308a7).(year));
190 }
191
192 static inline double msToMillisecondscxx . . $ QTWTF/msToMilliseconds(447c67c6676f75c3).(double ms)
193 {
194 double result = fmodcxx . . $ fmod(d8e7e0733fa41c87).(ms, msPerDaycxx . . $ QTWTF/msPerDay.);
195 if (result < 0)
196 result += msPerDaycxx . . $ QTWTF/msPerDay.;
197 return result;
198 }
199
200 // 0: Sunday, 1: Monday, etc.
201 static inline int msToWeekDaycxx . . $ QTWTF/msToWeekDay(620b9ac44d2573a6).(double ms)
202 {
203 int wd = (static_cast<int>(msToDayscxx . . $ QTWTF/msToDays(447c67c6676f75c3).(ms)) + 4) % 7;
204 if (wd < 0)
205 wd += 7;
206 return wd;
207 }
208
209 static inline int msToSecondscxx . . $ QTWTF/msToSeconds(620b9ac44d2573a6).(double ms)
210 {
211 double result = fmodcxx . . $ fmod(d8e7e0733fa41c87).(floorcxx . . $ floor(447c67c6676f75c3).(ms / msPerSecondcxx . . $ QTWTF/msPerSecond.), secondsPerMinutecxx . . $ QTWTF/secondsPerMinute.);
212 if (result < 0)
213 result += secondsPerMinutecxx . . $ QTWTF/secondsPerMinute.;
214 return static_cast<int>(result);
215 }
216
217 static inline int msToMinutescxx . . $ QTWTF/msToMinutes(620b9ac44d2573a6).(double ms)
218 {
219 double result = fmodcxx . . $ fmod(d8e7e0733fa41c87).(floorcxx . . $ floor(447c67c6676f75c3).(ms / msPerMinutecxx . . $ QTWTF/msPerMinute.), minutesPerHourcxx . . $ QTWTF/minutesPerHour.);
220 if (result < 0)
221 result += minutesPerHourcxx . . $ QTWTF/minutesPerHour.;
222 return static_cast<int>(result);
223 }
224
225 static inline int msToHourscxx . . $ QTWTF/msToHours(620b9ac44d2573a6).(double ms)
226 {
227 double result = fmodcxx . . $ fmod(d8e7e0733fa41c87).(floorcxx . . $ floor(447c67c6676f75c3).(ms/msPerHourcxx . . $ QTWTF/msPerHour.), hoursPerDaycxx . . $ QTWTF/hoursPerDay.);
228 if (result < 0)
229 result += hoursPerDaycxx . . $ QTWTF/hoursPerDay.;
230 return static_cast<int>(result);
231 }
232
233 int monthFromDayInYearcxx . . $ QTWTF/monthFromDayInYear(d455ce14f374a3ab).(int dayInYear, bool leapYear)
234 {
235 const int d = dayInYear;
236 int step;
237
238 if (d < (step = 31))
239 return 0;
240 step += (leapYear ? 29 : 28);
241 if (d < step)
242 return 1;
243 if (d < (step += 31))
244 return 2;
245 if (d < (step += 30))
246 return 3;
247 if (d < (step += 31))
248 return 4;
249 if (d < (step += 30))
250 return 5;
251 if (d < (step += 31))
252 return 6;
253 if (d < (step += 31))
254 return 7;
255 if (d < (step += 30))
256 return 8;
257 if (d < (step += 31))
258 return 9;
259 if (d < (step += 30))
260 return 10;
261 return 11;
262 }
263
264 static inline bool checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(int dayInYear, int& startDayOfThisMonth, int& startDayOfNextMonth, int daysInThisMonth)
265 {
266 startDayOfThisMonth = startDayOfNextMonth;
267 startDayOfNextMonth += daysInThisMonth;
268 return (dayInYear <= startDayOfNextMonth);
269 }
270
271 int dayInMonthFromDayInYearcxx . . $ QTWTF/dayInMonthFromDayInYear(d455ce14f374a3ab).(int dayInYear, bool leapYear)
272 {
273 const int d = dayInYear;
274 int step;
275 int next = 30;
276
277 if (d <= next)
278 return d + 1;
279 const int daysInFeb = (leapYear ? 29 : 28);
280 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, daysInFeb))
281 return d - step;
282 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 31))
283 return d - step;
284 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 30))
285 return d - step;
286 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 31))
287 return d - step;
288 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 30))
289 return d - step;
290 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 31))
291 return d - step;
292 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 31))
293 return d - step;
294 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 30))
295 return d - step;
296 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 31))
297 return d - step;
298 if (checkMonthcxx . . $ QTWTF/checkMonth(f4217350de0887b7).(d, step, next, 30))
299 return d - step;
300 step = next;
301 return d - step;
302 }
303
304 static inline int monthToDayInYearcxx . . $ QTWTF/monthToDayInYear(d455ce14f374a3ab).(int month, bool isLeapYear)
305 {
306 return firstDayOfMonthcxx . . $ QTWTF/firstDayOfMonth.[isLeapYear][month];
307 }
308
309 static inline double timeToMScxx . . $ QTWTF/timeToMS(6ba6c9f826937c6e).(double hour, double min, double sec, double ms)
310 {
311 return (((hour * minutesPerHourcxx . . $ QTWTF/minutesPerHour. + min) * secondsPerMinutecxx . . $ QTWTF/secondsPerMinute. + sec) * msPerSecondcxx . . $ QTWTF/msPerSecond. + ms);
312 }
313
314 double dateToDaysFrom1970cxx . . $ QTWTF/dateToDaysFrom1970(ec38aeb9d8f90526).(int year, int month, int day)
315 {
316 year += month / 12;
317
318 month %= 12;
319 if (month < 0) {
320 month += 12;
321 --year;
322 }
323
324 double yearday = floorcxx . . $ floor(447c67c6676f75c3).(daysFrom1970ToYearcxx . . $ QTWTF/daysFrom1970ToYear(4badf5dbac1308a7).(year));
325 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!((year >= 1970 && yearday >= 0) || (year < 1970 && yearday < 0));
326 int monthday = monthToDayInYearcxx . . $ QTWTF/monthToDayInYear(d455ce14f374a3ab).(month, isLeapYearcxx . . $ QTWTF/isLeapYear(83c267b20bac841a).(year));
327
328 return yearday + monthday + day - 1;
329 }
330
331 // There is a hard limit at 2038 that we currently do not have a workaround
332 // for (rdar://problem/5052975).
333 static inline int maximumYearForDSTcxx . . $ QTWTF/maximumYearForDST(b126dc7c1de90089).()
334 {
335 return 2037;
336 }
337
338 static inline int minimumYearForDSTcxx . . $ QTWTF/minimumYearForDST(b126dc7c1de90089).()
339 {
340 // Because of the 2038 issue (see maximumYearForDST) if the current year is
341 // greater than the max year minus 27 (2010), we want to use the max year
342 // minus 27 instead, to ensure there is a range of 28 years that all years
343 // can map to.
344 return stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(msToYearcxx . . $ QTWTF/msToYear(620b9ac44d2573a6).(jsCurrentTimecxx . . $ QTWTF/jsCurrentTime(31fa7155c10fdd13).()), maximumYearForDSTcxx . . $ QTWTF/maximumYearForDST(b126dc7c1de90089).() - 27) ;
345 }
346
347 /*
348 * Find an equivalent year for the one given, where equivalence is deterined by
349 * the two years having the same leapness and the first day of the year, falling
350 * on the same day of the week.
351 *
352 * This function returns a year between this current year and 2037, however this
353 * function will potentially return incorrect results if the current year is after
354 * 2010, (rdar://problem/5052975), if the year passed in is before 1900 or after
355 * 2100, (rdar://problem/5055038).
356 */
357 int equivalentYearForDSTcxx . . $ QTWTF/equivalentYearForDST(7864480464b09eea).(int year)
358 {
359 // It is ok if the cached year is not the current year as long as the rules
360 // for DST did not change between the two years; if they did the app would need
361 // to be restarted.
362 static int minYear = minimumYearForDSTcxx . . $ QTWTF/minimumYearForDST(b126dc7c1de90089).();
363 int maxYear = maximumYearForDSTcxx . . $ QTWTF/maximumYearForDST(b126dc7c1de90089).();
364
365 int difference;
366 if (year > maxYear)
367 difference = minYear - year;
368 else if (year < minYear)
369 difference = maxYear - year;
370 else
371 return year;
372
373 int quotient = difference / 28;
374 int product = (quotient) * 28;
375
376 year += product;
377 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!((year >= minYear && year <= maxYear) || (product - year == static_cast<int>(NaN)));
378 return year;
379 }
380
381 #if !HAVEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:46:9`!(TM_GMTOFF)
382
383 static int32_t calculateUTCOffset()
384 {
385 #if PLATFORM(BREWMP)
386 time_t localTime = static_cast<time_t>(currentTime());
387 #else
388 time_t localTime = time(0);
389 #endif
390 tm localt;
391 getLocalTime(&localTime, &localt);
392
393 // Get the difference between this time zone and UTC on the 1st of January of this year.
394 localt.tm_sec = 0;
395 localt.tm_min = 0;
396 localt.tm_hour = 0;
397 localt.tm_mday = 1;
398 localt.tm_mon = 0;
399 // Not setting localt.tm_year!
400 localt.tm_wday = 0;
401 localt.tm_yday = 0;
402 localt.tm_isdst = 0;
403 #if HAVE(TM_GMTOFF)
404 localt.tm_gmtoff = 0;
405 #endif
406 #if HAVE(TM_ZONE)
407 localt.tm_zone = 0;
408 #endif
409
410 #if HAVE(TIMEGM)
411 time_t utcOffset = timegm(&localt) - mktime(&localt);
412 #else
413 // Using a canned date of 01/01/2009 on platforms with weaker date-handling foo.
414 localt.tm_year = 109;
415 time_t utcOffset = 1230768000 - mktime(&localt);
416 #endif
417
418 return static_cast<int32_t>(utcOffset * 1000);
419 }
420
421 /*
422 * Get the DST offset for the time passed in.
423 */
424 static double calculateDSTOffset(time_t localTime, double utcOffset)
425 {
426 //input is UTC so we have to shift back to local time to determine DST thus the + getUTCOffset()
427 double offsetTime = (localTime * msPerSecond) + utcOffset;
428
429 // Offset from UTC but doesn't include DST obviously
430 int offsetHour = msToHours(offsetTime);
431 int offsetMinute = msToMinutes(offsetTime);
432
433 tm localTM;
434 getLocalTime(&localTime, &localTM);
435
436 double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.tm_min - offsetMinute) * 60);
437
438 if (diff < 0)
439 diff += secondsPerDay;
440
441 return (diff * msPerSecond);
442 }
443
444 #endif
445
446 // Returns combined offset in millisecond (UTC + DST).
447 LocalTimeOffsetcxx . . $ QTWTF/LocalTimeOffset# calculateLocalTimeOffsetcxx . . $ QTWTF/calculateLocalTimeOffset(1c25f9c1a4fcccfc).(double ms)
448 {
449 // On Mac OS X, the call to localtime (see calculateDSTOffset) will return historically accurate
450 // DST information (e.g. New Zealand did not have DST from 1946 to 1974) however the JavaScript
451 // standard explicitly dictates that historical information should not be considered when
452 // determining DST. For this reason we shift away from years that localtime can handle but would
453 // return historically accurate information.
454 int year = msToYearcxx . . $ QTWTF/msToYear(620b9ac44d2573a6).(ms);
455 int equivalentYear = equivalentYearForDSTcxx . . $ QTWTF/equivalentYearForDST(7864480464b09eea).(year);
456 if (year != equivalentYear) {
457 bool leapYear = isLeapYearcxx . . $ QTWTF/isLeapYear(83c267b20bac841a).(year);
458 int dayInYearLocal = dayInYearcxx . . $ QTWTF/dayInYear(73c075bbbf02e8eb).(ms, year);
459 int dayInMonth = dayInMonthFromDayInYearcxx . . $ QTWTF/dayInMonthFromDayInYear(d455ce14f374a3ab).(dayInYearLocal, leapYear);
460 int month = monthFromDayInYearcxx . . $ QTWTF/monthFromDayInYear(d455ce14f374a3ab).(dayInYearLocal, leapYear);
461 double day = dateToDaysFrom1970cxx . . $ QTWTF/dateToDaysFrom1970(ec38aeb9d8f90526).(equivalentYear, month, dayInMonth);
462 ms = (day * msPerDaycxx . . $ QTWTF/msPerDay.) + msToMillisecondscxx . . $ QTWTF/msToMilliseconds(447c67c6676f75c3).(ms);
463 }
464
465 double localTimeSeconds = ms / msPerSecondcxx . . $ QTWTF/msPerSecond.;
466 if (localTimeSeconds > maxUnixTimecxx . . $ QTWTF/maxUnixTime.)
467 localTimeSeconds = maxUnixTimecxx . . $ QTWTF/maxUnixTime.;
468 else if (localTimeSeconds < 0) // Go ahead a day to make localtime work (does not work with 0).
469 localTimeSeconds += secondsPerDaycxx . . $ QTWTF/secondsPerDay.;
470 // FIXME: time_t has a potential problem in 2038.
471 time_t localTime = static_cast<time_t>(localTimeSeconds);
472
473 #if HAVEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:46:9`!(TM_GMTOFF)
474 tmcxx . . $ tm# localTM;
475 getLocalTimecxx . . $ QTWTF/getLocalTime(309402b4d3edca5f).(&localTime, &localTM);
476 return LocalTimeOffsetcxx . . $ QTWTF/LocalTimeOffset#LocalTimeOffset(b994e01f1c45a386).(localTM.tm_isdstcxx . . $ tm#tm_isdst., localTM.tm_gmtoffcxx . . $ tm#tm_gmtoff. * msPerSecondcxx . . $ QTWTF/msPerSecond.);
477 #else
478 double utcOffset = calculateUTCOffset();
479 double dstOffset = calculateDSTOffset(localTime, utcOffset);
480 return LocalTimeOffset(dstOffset, utcOffset + dstOffset);
481 #endif
482 }
483
484 void initializeDatescxx . . $ QTWTF/initializeDates(49f6e7a06ebc5aa8).()
485 {
486 #ifndef NDEBUGcxx . . $ `<built-in>:472:9`!
487 static bool alreadyInitialized;
488 ASSERT(!alreadyInitialized);
489 alreadyInitialized = true;
490 #endif
491
492 equivalentYearForDSTcxx . . $ QTWTF/equivalentYearForDST(7864480464b09eea).(2000); // Need to call once to initialize a static used in this function.
493 }
494
495 static inline double ymdhmsToSecondscxx . . $ QTWTF/ymdhmsToSeconds(76897c140dc577d3).(long year, int mon, int day, int hour, int minute, int second)
496 {
497 double days = (day - 32075)
498 + floorcxx . . $ floor(447c67c6676f75c3).(1461 * (year + 4800.0 + (mon - 14) / 12) / 4)
499 + 367 * (mon - 2 - (mon - 14) / 12 * 12) / 12
500 - floorcxx . . $ floor(447c67c6676f75c3).(3 * ((year + 4900.0 + (mon - 14) / 12) / 100) / 4)
501 - 2440588;
502 return ((days * hoursPerDaycxx . . $ QTWTF/hoursPerDay. + hour) * minutesPerHourcxx . . $ QTWTF/minutesPerHour. + minute) * secondsPerMinutecxx . . $ QTWTF/secondsPerMinute. + second;
503 }
504
505 // We follow the recommendation of RFC 2822 to consider all
506 // obsolete time zones not listed here equivalent to "-0000".
507 static const struct KnownZonecxx . . $ QTWTF/KnownZone# {
508 #if !OScxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:49:9`!(WINDOWS)
509 const
510 #endif
511 char tzNamecxx . . $ QTWTF/KnownZone#tzName.[4];
512 int tzOffsetcxx . . $ QTWTF/KnownZone#tzOffset.;
513 } known_zonescxx . . $ QTWTF/known_zones.[] = {
514 { "UT", 0 },
515 { "GMT", 0 },
516 { "EST", -300 },
517 { "EDT", -240 },
518 { "CST", -360 },
519 { "CDT", -300 },
520 { "MST", -420 },
521 { "MDT", -360 },
522 { "PST", -480 },
523 { "PDT", -420 }
524 };
525
526 inline static void skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(const char*& s)
527 {
528 int nesting = 0;
529 char ch;
530 while ((ch = *s)) {
531 if (!isASCIISpacecxx . . $ QTWTF/isASCIISpace(b5fd09639b7a0261).(ch)) {
532 if (ch == '(')
533 nesting++;
534 else if (ch == ')' && nesting > 0)
535 nesting--;
536 else if (nesting == 0)
537 break;
538 }
539 s++;
540 }
541 }
542
543 // returns 0-11 (Jan-Dec); -1 on failure
544 static int findMonthcxx . . $ QTWTF/findMonth(5c4306d8553b3696).(const char* monthStr)
545 {
546 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(monthStr);
547 char needle[4];
548 for (int i = 0; i < 3; ++i) {
549 if (!*monthStr)
550 return -1;
551 needle[i] = static_cast<char>(toASCIILowercxx . . $ QTWTF/toASCIILower(e6e5e845b55315fc).(*monthStr++));
552 }
553 needle[3] = '\0';
554 const char *haystack = "janfebmaraprmayjunjulaugsepoctnovdec";
555 const char *str = strstr(haystack, needle);
556 if (str) {
557 int position = static_cast<int>(str - haystack);
558 if (position % 3 == 0)
559 return position / 3;
560 }
561 return -1;
562 }
563
564 static bool parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(const char* string, char** stopPosition, int base, long* result)
565 {
566 *result = strtolcxx . . $ strtol(44bbb87609b212fc).(string, stopPosition, base);
567 // Avoid the use of errno as it is not available on Windows CE
568 if (string == *stopPosition || *result == LONG_MINcxx . . $ `<external>/67164224788392828/limits.h:129:9`! || *result == LONG_MAXcxx . . $ `<external>/67164224788392828/limits.h:131:9`!)
569 return false;
570 return true;
571 }
572
573 // Odd case where 'exec' is allowed to be 0, to accomodate a caller in WebCore.
574 static double parseDateFromNullTerminatedCharacterscxx . . $ QTWTF/parseDateFromNullTerminatedCharacters(3b746d1ce77b91c9).(const char* dateString, bool& haveTZ, int& offset)
575 {
576 haveTZ = false;
577 offset = 0;
578
579 // This parses a date in the form:
580 // Tuesday, 09-Nov-99 23:12:40 GMT
581 // or
582 // Sat, 01-Jan-2000 08:00:00 GMT
583 // or
584 // Sat, 01 Jan 2000 08:00:00 GMT
585 // or
586 // 01 Jan 99 22:00 +0100 (exceptions in rfc822/rfc2822)
587 // ### non RFC formats, added for Javascript:
588 // [Wednesday] January 09 1999 23:12:40 GMT
589 // [Wednesday] January 09 23:12:40 GMT 1999
590 //
591 // We ignore the weekday.
592
593 // Skip leading space
594 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
595
596 long month = -1;
597 const char *wordStart = dateString;
598 // Check contents of first words if not number
599 while (*dateString && !isASCIIDigitcxx . . $ QTWTF/isASCIIDigit(b5fd09639b7a0261).(*dateString)) {
600 if (isASCIISpacecxx . . $ QTWTF/isASCIISpace(b5fd09639b7a0261).(*dateString) || *dateString == '(') {
601 if (dateString - wordStart >= 3)
602 month = findMonthcxx . . $ QTWTF/findMonth(5c4306d8553b3696).(wordStart);
603 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
604 wordStart = dateString;
605 } else
606 dateString++;
607 }
608
609 // Missing delimiter between month and day (like "January29")?
610 if (month == -1 && wordStart != dateString)
611 month = findMonthcxx . . $ QTWTF/findMonth(5c4306d8553b3696).(wordStart);
612
613 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
614
615 if (!*dateString)
616 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
617
618 // ' 09-Nov-99 23:12:40 GMT'
619 char* newPosStr;
620 long day;
621 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &day))
622 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
623 dateString = newPosStr;
624
625 if (!*dateString)
626 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
627
628 if (day < 0)
629 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
630
631 long year = 0;
632 if (day > 31) {
633 // ### where is the boundary and what happens below?
634 if (*dateString != '/')
635 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
636 // looks like a YYYY/MM/DD date
637 if (!*++dateString)
638 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
639 year = day;
640 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &month))
641 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
642 month -= 1;
643 dateString = newPosStr;
644 if (*dateString++ != '/' || !*dateString)
645 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
646 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &day))
647 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
648 dateString = newPosStr;
649 } else if (*dateString == '/' && month == -1) {
650 dateString++;
651 // This looks like a MM/DD/YYYY date, not an RFC date.
652 month = day - 1; // 0-based
653 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &day))
654 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
655 if (day < 1 || day > 31)
656 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
657 dateString = newPosStr;
658 if (*dateString == '/')
659 dateString++;
660 if (!*dateString)
661 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
662 } else {
663 if (*dateString == '-')
664 dateString++;
665
666 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
667
668 if (*dateString == ',')
669 dateString++;
670
671 if (month == -1) { // not found yet
672 month = findMonthcxx . . $ QTWTF/findMonth(5c4306d8553b3696).(dateString);
673 if (month == -1)
674 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
675
676 while (*dateString && *dateString != '-' && *dateString != ',' && !isASCIISpacecxx . . $ QTWTF/isASCIISpace(b5fd09639b7a0261).(*dateString))
677 dateString++;
678
679 if (!*dateString)
680 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
681
682 // '-99 23:12:40 GMT'
683 if (*dateString != '-' && *dateString != '/' && *dateString != ',' && !isASCIISpacecxx . . $ QTWTF/isASCIISpace(b5fd09639b7a0261).(*dateString))
684 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
685 dateString++;
686 }
687 }
688
689 if (month < 0 || month > 11)
690 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
691
692 // '99 23:12:40 GMT'
693 if (year <= 0 && *dateString) {
694 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &year))
695 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
696 }
697
698 // Don't fail if the time is missing.
699 long hour = 0;
700 long minute = 0;
701 long second = 0;
702 if (!*newPosStr)
703 dateString = newPosStr;
704 else {
705 // ' 23:12:40 GMT'
706 if (!(isASCIISpacecxx . . $ QTWTF/isASCIISpace(b5fd09639b7a0261).(*newPosStr) || *newPosStr == ',')) {
707 if (*newPosStr != ':')
708 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
709 // There was no year; the number was the hour.
710 year = -1;
711 } else {
712 // in the normal case (we parsed the year), advance to the next number
713 dateString = ++newPosStr;
714 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
715 }
716
717 parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &hour);
718 // Do not check for errno here since we want to continue
719 // even if errno was set becasue we are still looking
720 // for the timezone!
721
722 // Read a number? If not, this might be a timezone name.
723 if (newPosStr != dateString) {
724 dateString = newPosStr;
725
726 if (hour < 0 || hour > 23)
727 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
728
729 if (!*dateString)
730 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
731
732 // ':12:40 GMT'
733 if (*dateString++ != ':')
734 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
735
736 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &minute))
737 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
738 dateString = newPosStr;
739
740 if (minute < 0 || minute > 59)
741 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
742
743 // ':40 GMT'
744 if (*dateString && *dateString != ':' && !isASCIISpacecxx . . $ QTWTF/isASCIISpace(b5fd09639b7a0261).(*dateString))
745 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
746
747 // seconds are optional in rfc822 + rfc2822
748 if (*dateString ==':') {
749 dateString++;
750
751 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &second))
752 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
753 dateString = newPosStr;
754
755 if (second < 0 || second > 59)
756 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
757 }
758
759 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
760
761 if (strncasecmp(dateString, "AM", 2) == 0) {
762 if (hour > 12)
763 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
764 if (hour == 12)
765 hour = 0;
766 dateString += 2;
767 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
768 } else if (strncasecmp(dateString, "PM", 2) == 0) {
769 if (hour > 12)
770 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
771 if (hour != 12)
772 hour += 12;
773 dateString += 2;
774 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
775 }
776 }
777 }
778
779 // Don't fail if the time zone is missing.
780 // Some websites omit the time zone (4275206).
781 if (*dateString) {
782 if (strncasecmp(dateString, "GMT", 3) == 0 || strncasecmp(dateString, "UTC", 3) == 0) {
783 dateString += 3;
784 haveTZ = true;
785 }
786
787 if (*dateString == '+' || *dateString == '-') {
788 long o;
789 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &o))
790 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
791 dateString = newPosStr;
792
793 if (o < -9959 || o > 9959)
794 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
795
796 int sgn = (o < 0) ? -1 : 1;
797 o = labscxx . . $ labs(8ce0d1b217db7fd1).(o);
798 if (*dateString != ':') {
799 offset = ((o / 100) * 60 + (o % 100)) * sgn;
800 } else { // GMT+05:00
801 long o2;
802 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &o2))
803 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
804 dateString = newPosStr;
805 offset = (o * 60 + o2) * sgn;
806 }
807 haveTZ = true;
808 } else {
809 for (int i = 0; i < int(sizeof(known_zonescxx . . $ QTWTF/known_zones.) / sizeof(KnownZonecxx . . $ QTWTF/KnownZone#)); i++) {
810 if (0 == strncasecmp(dateString, known_zonescxx . . $ QTWTF/known_zones.[i].tzNamecxx . . $ QTWTF/KnownZone#tzName., strlen(known_zonescxx . . $ QTWTF/known_zones.[i].tzNamecxx . . $ QTWTF/KnownZone#tzName.))) {
811 offset = known_zonescxx . . $ QTWTF/known_zones.[i].tzOffsetcxx . . $ QTWTF/KnownZone#tzOffset.;
812 dateString += strlen(known_zonescxx . . $ QTWTF/known_zones.[i].tzNamecxx . . $ QTWTF/KnownZone#tzName.);
813 haveTZ = true;
814 break;
815 }
816 }
817 }
818 }
819
820 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
821
822 if (*dateString && year == -1) {
823 if (!parseLongcxx . . $ QTWTF/parseLong(c23e8214f5cbcea8).(dateString, &newPosStr, 10, &year))
824 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
825 dateString = newPosStr;
826 }
827
828 skipSpacesAndCommentscxx . . $ QTWTF/skipSpacesAndComments(30ad0281919313c0).(dateString);
829
830 // Trailing garbage
831 if (*dateString)
832 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
833
834 // Y2K: Handle 2 digit years.
835 if (year >= 0 && year < 100) {
836 if (year < 50)
837 year += 2000;
838 else
839 year += 1900;
840 }
841
842 return ymdhmsToSecondscxx . . $ QTWTF/ymdhmsToSeconds(76897c140dc577d3).(year, month + 1, day, hour, minute, second) * msPerSecondcxx . . $ QTWTF/msPerSecond.;
843 }
844
845 double parseDateFromNullTerminatedCharacterscxx . . $ QTWTF/parseDateFromNullTerminatedCharacters(9a18bdb0e56c1bc2).(const char* dateString)
846 {
847 bool haveTZ;
848 int offset;
849 double ms = parseDateFromNullTerminatedCharacterscxx . . $ QTWTF/parseDateFromNullTerminatedCharacters(3b746d1ce77b91c9).(dateString, haveTZ, offset);
850 if (stdcxx . . $ std/::isnan(ms))
851 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
852
853 // fall back to local timezone
854 if (!haveTZ)
855 offset = calculateLocalTimeOffsetcxx . . $ QTWTF/calculateLocalTimeOffset(1c25f9c1a4fcccfc).(ms).offsetcxx . . $ QTWTF/LocalTimeOffset#offset. / msPerMinutecxx . . $ QTWTF/msPerMinute.;
856
857 return ms - (offset * msPerMinutecxx . . $ QTWTF/msPerMinute.);
858 }
859
860 double timeClipcxx . . $ QTWTF/timeClip(447c67c6676f75c3).(double t)
861 {
862 if (!stdcxx . . $ std/::isfinite(t))
863 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
864 if (fabscxx . . $ fabs(447c67c6676f75c3).(t) > maxECMAScriptTimecxx . . $ QTWTF/maxECMAScriptTime.)
865 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
866 return trunccxx . . $ trunc(447c67c6676f75c3).(t);
867 }
868 } // namespace WTF
869
870 #if USEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:55:9`!(JSC)
871 namespace JSCcxx . . $ `<built-in>:463:9`! {
872
873 // Get the combined UTC + DST offset for the time passed in.
874 //
875 // NOTE: The implementation relies on the fact that no time zones have
876 // more than one daylight savings offset change per month.
877 // If this function is called with NaN it returns NaN.
878 static LocalTimeOffsetcxx . . $ LocalTimeOffset# localTimeOffsetcxx . . $ QTJSC/localTimeOffset(2cd609e874114f2f).(ExecStatecxx . . $ QTJSC/ExecState#* exec, double ms)
879 {
880 LocalTimeOffsetCachecxx . . $ QTJSC/LocalTimeOffsetCache#& cache = exec->globalDatacxx . . $ QTJSC/ExecState#globalData(ae00a65ac2fd4a61).().localTimeOffsetCachecxx . . $ QTJSC/JSGlobalData#localTimeOffsetCache.;
881 double start = cache.startcxx . . $ QTJSC/LocalTimeOffsetCache#start.;
882 double end = cache.endcxx . . $ QTJSC/LocalTimeOffsetCache#end.;
883
884 if (start <= ms) {
885 // If the time fits in the cached interval, return the cached offset.
886 if (ms <= end) return cache.offsetcxx . . $ QTJSC/LocalTimeOffsetCache#offset.;
887
888 // Compute a possible new interval end.
889 double newEnd = end + cache.incrementcxx . . $ QTJSC/LocalTimeOffsetCache#increment.;
890
891 if (ms <= newEnd) {
892 LocalTimeOffsetcxx . . $ LocalTimeOffset# endOffset = calculateLocalTimeOffsetcxx . . $ QTWTF/calculateLocalTimeOffset(1c25f9c1a4fcccfc).(newEnd);
893 if (cache.offsetcxx . . $ QTJSC/LocalTimeOffsetCache#offset. ==cxx . . $ QTWTF/LocalTimeOffset#`operator==`(ee6c6240dee66e24). endOffset) {
894 // If the offset at the end of the new interval still matches
895 // the offset in the cache, we grow the cached time interval
896 // and return the offset.
897 cache.endcxx . . $ QTJSC/LocalTimeOffsetCache#end. = newEnd;
898 cache.incrementcxx . . $ QTJSC/LocalTimeOffsetCache#increment. = msPerMonthcxx . . $ QTWTF/msPerMonth.;
899 return endOffset;
900 }
901 LocalTimeOffsetcxx . . $ LocalTimeOffset# offset = calculateLocalTimeOffsetcxx . . $ QTWTF/calculateLocalTimeOffset(1c25f9c1a4fcccfc).(ms);
902 if (offset ==cxx . . $ QTWTF/LocalTimeOffset#`operator==`(ee6c6240dee66e24). endOffset) {
903 // The offset at the given time is equal to the offset at the
904 // new end of the interval, so that means that we've just skipped
905 // the point in time where the DST offset change occurred. Updated
906 // the interval to reflect this and reset the increment.
907 cache.startcxx . . $ QTJSC/LocalTimeOffsetCache#start. = ms;
908 cache.endcxx . . $ QTJSC/LocalTimeOffsetCache#end. = newEnd;
909 cache.incrementcxx . . $ QTJSC/LocalTimeOffsetCache#increment. = msPerMonthcxx . . $ QTWTF/msPerMonth.;
910 } else {
911 // The interval contains a DST offset change and the given time is
912 // before it. Adjust the increment to avoid a linear search for
913 // the offset change point and change the end of the interval.
914 cache.incrementcxx . . $ QTJSC/LocalTimeOffsetCache#increment. /= 3;
915 cache.endcxx . . $ QTJSC/LocalTimeOffsetCache#end. = ms;
916 }
917 // Update the offset in the cache and return it.
918 cache.offsetcxx . . $ QTJSC/LocalTimeOffsetCache#offset. =cxx . . $ QTWTF/LocalTimeOffset#`operator=`(ce78332ccac95c0e). offset;
919 return offset;
920 }
921 }
922
923 // Compute the DST offset for the time and shrink the cache interval
924 // to only contain the time. This allows fast repeated DST offset
925 // computations for the same time.
926 LocalTimeOffsetcxx . . $ LocalTimeOffset# offset = calculateLocalTimeOffsetcxx . . $ QTWTF/calculateLocalTimeOffset(1c25f9c1a4fcccfc).(ms);
927 cache.offsetcxx . . $ QTJSC/LocalTimeOffsetCache#offset. =cxx . . $ QTWTF/LocalTimeOffset#`operator=`(ce78332ccac95c0e). offset;
928 cache.startcxx . . $ QTJSC/LocalTimeOffsetCache#start. = ms;
929 cache.endcxx . . $ QTJSC/LocalTimeOffsetCache#end. = ms;
930 cache.incrementcxx . . $ QTJSC/LocalTimeOffsetCache#increment. = msPerMonthcxx . . $ QTWTF/msPerMonth.;
931 return offset;
932 }
933
934 double gregorianDateTimeToMScxx . . $ QTJSC/gregorianDateTimeToMS(cc17aa427b3e2ce3).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const GregorianDateTimecxx . . $ QTJSC/GregorianDateTime#& t, double milliSeconds, bool inputIsUTC)
935 {
936 double day = dateToDaysFrom1970cxx . . $ QTWTF/dateToDaysFrom1970(ec38aeb9d8f90526).(t.yearcxx . . $ QTJSC/GregorianDateTime#year. + 1900, t.monthcxx . . $ QTJSC/GregorianDateTime#month., t.monthDaycxx . . $ QTJSC/GregorianDateTime#monthDay.);
937 double ms = timeToMScxx . . $ QTWTF/timeToMS(6ba6c9f826937c6e).(t.hourcxx . . $ QTJSC/GregorianDateTime#hour., t.minutecxx . . $ QTJSC/GregorianDateTime#minute., t.secondcxx . . $ QTJSC/GregorianDateTime#second., milliSeconds);
938 double result = (day * WTFcxx . . $ `<built-in>:467:9`!::msPerDaycxx . . $ QTWTF/msPerDay.) + ms;
939
940 if (!inputIsUTC)
941 result -= localTimeOffsetcxx . . $ QTJSC/localTimeOffset(2cd609e874114f2f).(exec, result).offsetcxx . . $ QTWTF/LocalTimeOffset#offset.;
942
943 return result;
944 }
945
946 // input is UTC
947 void msToGregorianDateTimecxx . . $ QTJSC/msToGregorianDateTime(5de9dac720d4db69).(ExecStatecxx . . $ QTJSC/ExecState#* exec, double ms, bool outputIsUTC, GregorianDateTimecxx . . $ QTJSC/GregorianDateTime#& tm)
948 {
949 LocalTimeOffsetcxx . . $ LocalTimeOffset# localTimecxx . . $ QTWTF/LocalTimeOffset#LocalTimeOffset(b994e01f1c45a386).(false, 0);
950 if (!outputIsUTC) {
951 localTime =cxx . . $ QTWTF/LocalTimeOffset#`operator=`(570c03fa682bee86). localTimeOffsetcxx . . $ QTJSC/localTimeOffset(2cd609e874114f2f).(exec, ms);
952 ms += localTime.offsetcxx . . $ QTWTF/LocalTimeOffset#offset.;
953 }
954
955 const int year = msToYearcxx . . $ QTWTF/msToYear(620b9ac44d2573a6).(ms);
956 tm.secondcxx . . $ QTJSC/GregorianDateTime#second. = msToSecondscxx . . $ QTWTF/msToSeconds(620b9ac44d2573a6).(ms);
957 tm.minutecxx . . $ QTJSC/GregorianDateTime#minute. = msToMinutescxx . . $ QTWTF/msToMinutes(620b9ac44d2573a6).(ms);
958 tm.hourcxx . . $ QTJSC/GregorianDateTime#hour. = msToHourscxx . . $ QTWTF/msToHours(620b9ac44d2573a6).(ms);
959 tm.weekDaycxx . . $ QTJSC/GregorianDateTime#weekDay. = msToWeekDaycxx . . $ QTWTF/msToWeekDay(620b9ac44d2573a6).(ms);
960 tm.yearDaycxx . . $ QTJSC/GregorianDateTime#yearDay. = dayInYearcxx . . $ QTWTF/dayInYear(73c075bbbf02e8eb).(ms, year);
961 tm.monthDaycxx . . $ QTJSC/GregorianDateTime#monthDay. = dayInMonthFromDayInYearcxx . . $ QTWTF/dayInMonthFromDayInYear(d455ce14f374a3ab).(tm.yearDaycxx . . $ QTJSC/GregorianDateTime#yearDay., isLeapYearcxx . . $ QTWTF/isLeapYear(83c267b20bac841a).(year));
962 tm.monthcxx . . $ QTJSC/GregorianDateTime#month. = monthFromDayInYearcxx . . $ QTWTF/monthFromDayInYear(d455ce14f374a3ab).(tm.yearDaycxx . . $ QTJSC/GregorianDateTime#yearDay., isLeapYearcxx . . $ QTWTF/isLeapYear(83c267b20bac841a).(year));
963 tm.yearcxx . . $ QTJSC/GregorianDateTime#year. = year - 1900;
964 tm.isDSTcxx . . $ QTJSC/GregorianDateTime#isDST. = localTime.isDSTcxx . . $ QTWTF/LocalTimeOffset#isDST.;
965 tm.utcOffsetcxx . . $ QTJSC/GregorianDateTime#utcOffset. = localTime.offsetcxx . . $ QTWTF/LocalTimeOffset#offset. / WTFcxx . . $ `<built-in>:467:9`!::msPerSecondcxx . . $ QTWTF/msPerSecond.;
966 tm.timeZonecxx . . $ QTJSC/GregorianDateTime#timeZone. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
967 }
968
969 double parseDateFromNullTerminatedCharacterscxx . . $ QTJSC/parseDateFromNullTerminatedCharacters(e1ee60001899bbeb).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const char* dateString)
970 {
971 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(exec);
972 bool haveTZ;
973 int offset;
974 double ms = WTFcxx . . $ `<built-in>:467:9`!::parseDateFromNullTerminatedCharacterscxx . . $ QTWTF/parseDateFromNullTerminatedCharacters(3b746d1ce77b91c9).(dateString, haveTZ, offset);
975 if (stdcxx . . $ std/::isnan(ms))
976 return NaNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/DateMath.cpp:109:9`!;
977
978 // fall back to local timezone
979 if (!haveTZ)
980 offset = calculateLocalTimeOffsetcxx . . $ QTWTF/calculateLocalTimeOffset(1c25f9c1a4fcccfc).(ms).offsetcxx . . $ QTWTF/LocalTimeOffset#offset. / msPerMinutecxx . . $ QTWTF/msPerMinute.;
981
982 return ms - (offset * WTFcxx . . $ `<built-in>:467:9`!::msPerMinutecxx . . $ QTWTF/msPerMinute.);
983 }
984
985 } // namespace JSC
986 #endif // USE(JSC)