[V8] Remove dependency on _mkgmtime to determine local timezone offset
authorJonathan Liu <net147@gmail.com>
Tue, 27 Mar 2012 09:56:36 +0000 (20:56 +1100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 27 Mar 2012 10:09:13 +0000 (12:09 +0200)
This fixes "new Date()" returning wrong hour and time zone offset with
MinGW.

Upstream patch: https://chromiumcodereview.appspot.com/9600018

Change-Id: I00036ce7c3c5b8586c4c1eaa41facf792ef0f0e6
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
src/3rdparty/v8/src/platform-win32.cc

index 97159aa..537440b 100644 (file)
@@ -65,16 +65,8 @@ int fopen_s(FILE** pFile, const char* filename, const char* mode) {
 
 
 #ifndef __MINGW64_VERSION_MAJOR
-
-// Not sure this the correct interpretation of _mkgmtime
-time_t _mkgmtime(tm* timeptr) {
-  return mktime(timeptr);
-}
-
-
 #define _TRUNCATE 0
 #define STRUNCATE 80
-
 #endif  // __MINGW64_VERSION_MAJOR
 
 
@@ -491,11 +483,13 @@ int64_t Time::LocalOffset() {
   // Convert to local time, as struct with fields for day, hour, year, etc.
   tm posix_local_time_struct;
   if (localtime_s(&posix_local_time_struct, &posix_time)) return 0;
-  // Convert local time in struct to POSIX time as if it were a UTC time.
-  time_t local_posix_time = _mkgmtime(&posix_local_time_struct);
-  Time localtime(1000.0 * local_posix_time);
 
-  return localtime.Diff(&rounded_to_second);
+  if (posix_local_time_struct.tm_isdst > 0)
+      return (tzinfo_.Bias + tzinfo_.DaylightBias) * -kMsPerMinute;
+  else if (posix_local_time_struct.tm_isdst == 0)
+      return (tzinfo_.Bias + tzinfo_.StandardBias) * -kMsPerMinute;
+  else
+      return tzinfo_.Bias * -kMsPerMinute;
 }