| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/os.h" | 5 #include "vm/os.h" |
| 6 | 6 |
| 7 #include <time.h> | 7 #include <time.h> |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 } else { | 29 } else { |
| 30 return static_cast<int>(zone_information.DaylightBias * 60); | 30 return static_cast<int>(zone_information.DaylightBias * 60); |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 | 34 |
| 35 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { | 35 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { |
| 36 tm decomposed; | 36 tm decomposed; |
| 37 // LocalTime will set _tzname. | 37 // LocalTime will set _tzname. |
| 38 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); | 38 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
| 39 ASSERT(succeeded); | 39 if (succeeded) { |
| 40 int inDaylightSavingsTime = decomposed.tm_isdst; | 40 int inDaylightSavingsTime = decomposed.tm_isdst; |
| 41 ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1); | 41 ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1); |
| 42 return _tzname[inDaylightSavingsTime]; | 42 return _tzname[inDaylightSavingsTime]; |
| 43 } else { |
| 44 // Return an empty string like V8 does. |
| 45 return ""; |
| 46 } |
| 43 } | 47 } |
| 44 | 48 |
| 45 | 49 |
| 46 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { | 50 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { |
| 47 tm decomposed; | 51 tm decomposed; |
| 48 // LocalTime will set _timezone. | 52 // LocalTime will set _timezone. |
| 49 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); | 53 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
| 50 ASSERT(succeeded); | 54 if (succeeded) { |
| 51 int inDaylightSavingsTime = decomposed.tm_isdst; | 55 int inDaylightSavingsTime = decomposed.tm_isdst; |
| 52 ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1); | 56 ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1); |
| 53 // Dart and Windows disagree on the sign of the bias. | 57 // Dart and Windows disagree on the sign of the bias. |
| 54 int offset = static_cast<int>(-_timezone); | 58 int offset = static_cast<int>(-_timezone); |
| 55 if (inDaylightSavingsTime == 1) { | 59 if (inDaylightSavingsTime == 1) { |
| 56 static int daylight_bias = GetDaylightSavingBiasInSeconds(); | 60 static int daylight_bias = GetDaylightSavingBiasInSeconds(); |
| 57 // Subtract because windows and Dart disagree on the sign. | 61 // Subtract because windows and Dart disagree on the sign. |
| 58 offset = offset - daylight_bias; | 62 offset = offset - daylight_bias; |
| 63 } |
| 64 return offset; |
| 65 } else { |
| 66 // Return zero like V8 does. |
| 67 return 0; |
| 59 } | 68 } |
| 60 return offset; | |
| 61 } | 69 } |
| 62 | 70 |
| 63 | 71 |
| 64 int OS::GetLocalTimeZoneAdjustmentInSeconds() { | 72 int OS::GetLocalTimeZoneAdjustmentInSeconds() { |
| 65 // TODO(floitsch): avoid excessive calls to _tzset? | 73 // TODO(floitsch): avoid excessive calls to _tzset? |
| 66 _tzset(); | 74 _tzset(); |
| 67 // Dart and Windows disagree on the sign of the bias. | 75 // Dart and Windows disagree on the sign of the bias. |
| 68 return static_cast<int>(-_timezone); | 76 return static_cast<int>(-_timezone); |
| 69 } | 77 } |
| 70 | 78 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 void OS::Abort() { | 241 void OS::Abort() { |
| 234 abort(); | 242 abort(); |
| 235 } | 243 } |
| 236 | 244 |
| 237 | 245 |
| 238 void OS::Exit(int code) { | 246 void OS::Exit(int code) { |
| 239 exit(code); | 247 exit(code); |
| 240 } | 248 } |
| 241 | 249 |
| 242 } // namespace dart | 250 } // namespace dart |
| OLD | NEW |