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

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

Issue 9969098: Set the TZ env to get the UTC-ms since epoch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments and rebased. Created 8 years, 8 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
« runtime/vm/os_macos.cc ('K') | « runtime/vm/os_macos.cc ('k') | no next file » | 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
11 namespace dart { 11 namespace dart {
12 12
13 bool OS::BreakDownSecondsSinceEpoch(time_t seconds_since_epoch, 13 bool OS::BreakDownSecondsSinceEpoch(time_t seconds_since_epoch,
14 bool in_utc, 14 bool in_utc,
15 BrokenDownDate* result) { 15 BrokenDownDate* result) {
16 struct tm tm_result; 16 struct tm tm_result;
17 errno_t error_code; 17 errno_t error_code;
18 if (in_utc) { 18 if (in_utc) {
19 error_code = gmtime_s(&tm_result, &seconds_since_epoch); 19 error_code = gmtime_s(&tm_result, &seconds_since_epoch);
20 } else { 20 } else {
21 // TODO(floitsch): we should be able to call tzset only once during
22 // initialization.
23 tzset(); // Make sure the libc knows about the local zone.
cshapiro 2012/04/19 23:52:12 Why was this removed? The documentation states th
floitsch 2012/04/20 16:09:57 localtime_s only looks at the env variable. tzset
24 error_code = localtime_s(&tm_result, &seconds_since_epoch); 21 error_code = localtime_s(&tm_result, &seconds_since_epoch);
25 } 22 }
26 result->year = tm_result.tm_year; 23 result->year = tm_result.tm_year;
27 result->month= tm_result.tm_mon; 24 result->month= tm_result.tm_mon;
28 result->day = tm_result.tm_mday; 25 result->day = tm_result.tm_mday;
29 result->hours = tm_result.tm_hour; 26 result->hours = tm_result.tm_hour;
30 result->minutes = tm_result.tm_min; 27 result->minutes = tm_result.tm_min;
31 result->seconds = tm_result.tm_sec; 28 result->seconds = tm_result.tm_sec;
32 return error_code == 0; 29 return error_code == 0;
33 } 30 }
34 31
35 32
36 bool OS::BrokenDownToSecondsSinceEpoch( 33 bool OS::BrokenDownToSecondsSinceEpoch(
37 const BrokenDownDate& broken_down, bool in_utc, time_t* result) { 34 const BrokenDownDate& broken_down, bool in_utc, time_t* result) {
38 struct tm tm_broken_down; 35 struct tm tm_broken_down;
39 // mktime takes the years since 1900. 36 // mktime takes the years since 1900.
40 tm_broken_down.tm_year = broken_down.year; 37 tm_broken_down.tm_year = broken_down.year;
41 tm_broken_down.tm_mon = broken_down.month; 38 tm_broken_down.tm_mon = broken_down.month;
42 tm_broken_down.tm_mday = broken_down.day; 39 tm_broken_down.tm_mday = broken_down.day;
43 tm_broken_down.tm_hour = broken_down.hours; 40 tm_broken_down.tm_hour = broken_down.hours;
44 tm_broken_down.tm_min = broken_down.minutes; 41 tm_broken_down.tm_min = broken_down.minutes;
45 tm_broken_down.tm_sec = broken_down.seconds; 42 tm_broken_down.tm_sec = broken_down.seconds;
46 // Set wday to an impossible day, so that we can catch bad input. 43 // Set wday to an impossible day, so that we can catch bad input.
47 tm_broken_down.tm_wday = -1; 44 tm_broken_down.tm_wday = -1;
48 // Make sure the libc knows about the local zone. 45 // Make sure the libc knows about the local zone.
49 // In case of 'in_utc' this call is mainly for multi-threading issues. If
50 // another thread uses a time-function it will set the timezone. The timezone
51 // adjustement below would then not work anymore.
52 // TODO(floitsch): we should be able to call tzset only once during 46 // TODO(floitsch): we should be able to call tzset only once during
53 // initialization. 47 // initialization.
54 tzset(); 48 tzset();
cshapiro 2012/04/19 23:52:12 Why is this being called before a conversion for a
floitsch 2012/04/20 16:09:57 Looking through the docs it looks as calling tzset
55 if (in_utc) { 49 if (in_utc) {
56 // Disable daylight saving in utc mode. 50 // Disable daylight saving in utc mode.
57 tm_broken_down.tm_isdst = 0; 51 tm_broken_down.tm_isdst = 0;
58 // mktime assumes that the given date is local time zone. 52 *result = _mkgmtime(&tm_broken_down);
59 *result = mktime(&tm_broken_down);
60 // Remove the timezone.
61 *result -= timezone;
62 } else { 53 } else {
63 // Let libc figure out if daylight saving is active. 54 // Let libc figure out if daylight saving is active.
64 tm_broken_down.tm_isdst = -1; 55 tm_broken_down.tm_isdst = -1;
65 *result = mktime(&tm_broken_down); 56 *result = mktime(&tm_broken_down);
66 } 57 }
67 if ((*result == -1) && (tm_broken_down.tm_wday == -1)) { 58 if ((*result == -1 || *result == 1) && (tm_broken_down.tm_wday == -1)) {
cshapiro 2012/04/19 23:52:12 How is returning 1 an error?
floitsch 2012/04/20 16:09:57 Couldn't find any reference to it either. Probably
68 return false; 59 return false;
69 } 60 }
70 return true; 61 return true;
71 } 62 }
72 63
73 64
74 int64_t OS::GetCurrentTimeMillis() { 65 int64_t OS::GetCurrentTimeMillis() {
75 return GetCurrentTimeMicros() / 1000; 66 return GetCurrentTimeMicros() / 1000;
76 } 67 }
77 68
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 void OS::Abort() { 198 void OS::Abort() {
208 abort(); 199 abort();
209 } 200 }
210 201
211 202
212 void OS::Exit(int code) { 203 void OS::Exit(int code) {
213 exit(code); 204 exit(code);
214 } 205 }
215 206
216 } // namespace dart 207 } // namespace dart
OLDNEW
« runtime/vm/os_macos.cc ('K') | « runtime/vm/os_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698