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

Side by Side Diff: runtime/vm/os_win.cc

Issue 10383218: Add support for timezone offset and timezone name. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/os_macos.cc ('k') | tests/corelib/date_time7_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 tm->tm_wday = -1; 47 tm->tm_wday = -1;
48 time_t seconds = mktime(tm); 48 time_t seconds = mktime(tm);
49 if ((seconds == -1) && (tm->tm_wday == -1)) { 49 if ((seconds == -1) && (tm->tm_wday == -1)) {
50 return false; 50 return false;
51 } 51 }
52 *seconds_result = seconds; 52 *seconds_result = seconds;
53 return true; 53 return true;
54 } 54 }
55 55
56 56
57 // Calls _tzset if necessary.
58 static void TzSet() {
59 static bool tz_is_initialized = false;
60 if (!tz_is_initialized) {
61 _tzset();
62 tz_is_initialized = true;
63 }
64 }
65
66
67 int GetDaylightSavingOffsetInSeconds() {
Mads Ager (google) 2012/05/21 12:53:28 static int GetDaylightSavingsOffsetInSeconds() {
floitsch 2012/05/21 13:26:45 Done.
68 TzSet();
Mads Ager (google) 2012/05/21 12:53:28 Is the call to TzSet needed here?
floitsch 2012/05/21 13:26:45 No. Apparently not. Removed.
69 TIME_ZONE_INFORMATION zone_information;
70 memset(&zone_information, 0, sizeof(zone_information));
71 if (GetTimeZoneInformation(&zone_information) == TIME_ZONE_ID_INVALID) {
72 // By default the daylight saving offset is an hour.
73 return -60 * 60;
74 } else {
75 return static_cast<int>(zone_information.DaylightBias * 60);
76 }
77 }
78
79 bool OS::GetTimeZoneName(int64_t seconds_since_epoch,
Mads Ager (google) 2012/05/21 12:53:28 There is a TzSet() call missing in this method I t
floitsch 2012/05/21 13:26:45 Updated comment: LocalTime implicitly calls tzset.
80 const char** name_result) {
81 tm decomposed;
82 bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
83 if (!succeeded) return false;
84 int inDaylightSavingsTime = decomposed.tm_isdst;
85 if (inDaylightSavingsTime != 0 && inDaylightSavingsTime != 1) {
86 return false;
87 }
88 *name_result = _tzname[inDaylightSavingsTime];
89 return true;
90 }
91
92
93 bool OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch,
94 int* offset_result) {
95 tm decomposed;
96 bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
97 if (!succeeded) return false;
98 int inDaylightSavingsTime = decomposed.tm_isdst;
99 if (inDaylightSavingsTime != 0 && inDaylightSavingsTime != 1) return false;
Mads Ager (google) 2012/05/21 12:53:28 Either a one-liner above or split into lines with
floitsch 2012/05/21 13:26:45 Done.
100 TzSet();
101 // Dart and Windows disagree on the sign of the bias.
102 *offset_result = static_cast<int>(-_timezone);
103 if (inDaylightSavingsTime == 1) {
104 static int daylight_offset = GetDaylightSavingOffsetInSeconds()
105 // Subtract because windows and Dart disagree on the sign.
106 *offset_result -= daylight_offset;
107 }
108 return true;
109 }
110
111
57 int64_t OS::GetCurrentTimeMillis() { 112 int64_t OS::GetCurrentTimeMillis() {
58 return GetCurrentTimeMicros() / 1000; 113 return GetCurrentTimeMicros() / 1000;
59 } 114 }
60 115
61 116
62 int64_t OS::GetCurrentTimeMicros() { 117 int64_t OS::GetCurrentTimeMicros() {
63 static const int64_t kTimeEpoc = 116444736000000000LL; 118 static const int64_t kTimeEpoc = 116444736000000000LL;
64 static const int64_t kTimeScaler = 10; // 100 ns to us. 119 static const int64_t kTimeScaler = 10; // 100 ns to us.
65 120
66 // Although win32 uses 64-bit integers for representing timestamps, 121 // Although win32 uses 64-bit integers for representing timestamps,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 void OS::Abort() { 251 void OS::Abort() {
197 abort(); 252 abort();
198 } 253 }
199 254
200 255
201 void OS::Exit(int code) { 256 void OS::Exit(int code) {
202 exit(code); 257 exit(code);
203 } 258 }
204 259
205 } // namespace dart 260 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/os_macos.cc ('k') | tests/corelib/date_time7_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698