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

Side by Side Diff: runtime/vm/os_macos.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: Address comments. 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_linux.cc ('k') | runtime/vm/os_win.cc » ('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 <errno.h> 7 #include <errno.h>
8 #include <limits.h> 8 #include <limits.h>
9 #include <mach/mach.h> 9 #include <mach/mach.h>
10 #include <mach/clock.h> 10 #include <mach/clock.h>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 tm->tm_wday = -1; 53 tm->tm_wday = -1;
54 time_t seconds = mktime(tm); 54 time_t seconds = mktime(tm);
55 if ((seconds == -1) && (tm->tm_wday == -1)) { 55 if ((seconds == -1) && (tm->tm_wday == -1)) {
56 return false; 56 return false;
57 } 57 }
58 *seconds_result = seconds; 58 *seconds_result = seconds;
59 return true; 59 return true;
60 } 60 }
61 61
62 62
63 bool OS::GetTimeZoneName(int64_t seconds_since_epoch,
64 const char** name_result) {
65 tm decomposed;
66 bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
67 if (!succeeded) return false;
68 *name_result = decomposed.tm_zone;
69 return true;
70 }
71
72
73 bool OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch,
74 int* offset_result) {
75 tm decomposed;
76 bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
77 if (!succeeded) return false;
78 // Even if the offset was 24 hours it would still easily fit into 32 bits.
79 *offset_result = static_cast<int>(decomposed.tm_gmtoff);
80 return true;
81 }
82
83
63 int64_t OS::GetCurrentTimeMillis() { 84 int64_t OS::GetCurrentTimeMillis() {
64 return GetCurrentTimeMicros() / 1000; 85 return GetCurrentTimeMicros() / 1000;
65 } 86 }
66 87
67 88
68 int64_t OS::GetCurrentTimeMicros() { 89 int64_t OS::GetCurrentTimeMicros() {
69 // gettimeofday has microsecond resolution. 90 // gettimeofday has microsecond resolution.
70 struct timeval tv; 91 struct timeval tv;
71 if (gettimeofday(&tv, NULL) < 0) { 92 if (gettimeofday(&tv, NULL) < 0) {
72 UNREACHABLE(); 93 UNREACHABLE();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 void OS::Abort() { 195 void OS::Abort() {
175 abort(); 196 abort();
176 } 197 }
177 198
178 199
179 void OS::Exit(int code) { 200 void OS::Exit(int code) {
180 exit(code); 201 exit(code);
181 } 202 }
182 203
183 } // namespace dart 204 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698