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

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

Issue 394903004: document.lastModified should consider user's local time zone (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Finger crossed Created 6 years, 5 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
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 return year; 351 return year;
352 352
353 int quotient = difference / 28; 353 int quotient = difference / 28;
354 int product = (quotient) * 28; 354 int product = (quotient) * 28;
355 355
356 year += product; 356 year += product;
357 ASSERT((year >= minYear && year <= maxYear) || (product - year == static_cas t<int>(std::numeric_limits<double>::quiet_NaN()))); 357 ASSERT((year >= minYear && year <= maxYear) || (product - year == static_cas t<int>(std::numeric_limits<double>::quiet_NaN())));
358 return year; 358 return year;
359 } 359 }
360 360
361 int32_t calculateUTCOffset() 361 static int32_t calculateUTCOffset()
362 { 362 {
363 #if OS(WIN) 363 #if OS(WIN)
364 TIME_ZONE_INFORMATION timeZoneInformation; 364 TIME_ZONE_INFORMATION timeZoneInformation;
365 GetTimeZoneInformation(&timeZoneInformation); 365 GetTimeZoneInformation(&timeZoneInformation);
366 int32_t bias = timeZoneInformation.Bias + timeZoneInformation.StandardBias; 366 int32_t bias = timeZoneInformation.Bias + timeZoneInformation.StandardBias;
367 return -bias * 60 * 1000; 367 return -bias * 60 * 1000;
368 #else 368 #else
369 time_t localTime = time(0); 369 time_t localTime = time(0);
370 tm localt; 370 tm localt;
371 getLocalTime(&localTime, &localt); 371 getLocalTime(&localTime, &localt);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 424
425 double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM. tm_min - offsetMinute) * 60); 425 double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM. tm_min - offsetMinute) * 60);
426 426
427 if (diff < 0) 427 if (diff < 0)
428 diff += secondsPerDay; 428 diff += secondsPerDay;
429 429
430 return (diff * msPerSecond); 430 return (diff * msPerSecond);
431 } 431 }
432 432
433 // Get the DST offset, given a time in UTC 433 // Get the DST offset, given a time in UTC
434 double calculateDSTOffset(double ms, double utcOffset) 434 static double calculateDSTOffset(double ms, double utcOffset)
435 { 435 {
436 // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will re turn historically accurate 436 // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will re turn historically accurate
437 // DST information (e.g. New Zealand did not have DST from 1946 to 1974) how ever the JavaScript 437 // DST information (e.g. New Zealand did not have DST from 1946 to 1974) how ever the JavaScript
438 // standard explicitly dictates that historical information should not be co nsidered when 438 // standard explicitly dictates that historical information should not be co nsidered when
439 // determining DST. For this reason we shift away from years that localtime can handle but would 439 // determining DST. For this reason we shift away from years that localtime can handle but would
440 // return historically accurate information. 440 // return historically accurate information.
441 int year = msToYear(ms); 441 int year = msToYear(ms);
442 int equivalentYear = equivalentYearForDST(year); 442 int equivalentYear = equivalentYearForDST(year);
443 if (year != equivalentYear) { 443 if (year != equivalentYear) {
444 bool leapYear = isLeapYear(year); 444 bool leapYear = isLeapYear(year);
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 stringBuilder.append(' '); 874 stringBuilder.append(' ');
875 875
876 stringBuilder.append(utcOffset > 0 ? '+' : '-'); 876 stringBuilder.append(utcOffset > 0 ? '+' : '-');
877 int absoluteUTCOffset = abs(utcOffset); 877 int absoluteUTCOffset = abs(utcOffset);
878 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset / 60)); 878 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset / 60));
879 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset % 60)); 879 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset % 60));
880 880
881 return stringBuilder.toString(); 881 return stringBuilder.toString();
882 } 882 }
883 883
884 double convertToLocalTime(double ms)
885 {
886 double utcOffset = calculateUTCOffset();
887 double dstOffset = calculateDSTOffset(ms, utcOffset);
888 return (ms + utcOffset + dstOffset);
889 }
890
884 } // namespace WTF 891 } // namespace WTF
OLDNEW
« LayoutTests/http/tests/misc/last-modified-parsing.html ('K') | « Source/wtf/DateMath.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698