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

Unified Diff: runtime/vm/os_macos.cc

Issue 10534111: Revert "Refactor Date implementation in VM." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_macos.cc
diff --git a/runtime/vm/os_macos.cc b/runtime/vm/os_macos.cc
index 7910b828ecb1db27cdbf10806e390f2cdc7b0dd1..3936e99e93ea46546e6623ca1749ec72d25977cc 100644
--- a/runtime/vm/os_macos.cc
+++ b/runtime/vm/os_macos.cc
@@ -18,7 +18,15 @@
namespace dart {
-static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
+bool OS::GmTime(int64_t seconds_since_epoch, tm* tm_result) {
+ time_t seconds = static_cast<time_t>(seconds_since_epoch);
+ if (seconds != seconds_since_epoch) return false;
+ struct tm* error_code = gmtime_r(&seconds, tm_result);
+ return error_code != NULL;
+}
+
+
+bool OS::LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
time_t seconds = static_cast<time_t>(seconds_since_epoch);
if (seconds != seconds_since_epoch) return false;
struct tm* error_code = localtime_r(&seconds, tm_result);
@@ -26,29 +34,50 @@ static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
}
-const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) {
- tm decomposed;
- bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
- ASSERT(succeeded);
- return decomposed.tm_zone;
+bool OS::MkGmTime(tm* tm, int64_t* seconds_result) {
+ // Set wday to an impossible day, so that we can catch bad input.
+ tm->tm_wday = -1;
+ time_t seconds = timegm(tm);
+ if ((seconds == -1) && (tm->tm_wday == -1)) {
+ return false;
+ }
+ *seconds_result = seconds;
+ return true;
+}
+
+
+bool OS::MkTime(tm* tm, int64_t* seconds_result) {
+ // Let the libc figure out if daylight saving is active.
+ tm->tm_isdst = -1;
+ // Set wday to an impossible day, so that we can catch bad input.
+ tm->tm_wday = -1;
+ time_t seconds = mktime(tm);
+ if ((seconds == -1) && (tm->tm_wday == -1)) {
+ return false;
+ }
+ *seconds_result = seconds;
+ return true;
}
-int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) {
+bool OS::GetTimeZoneName(int64_t seconds_since_epoch,
+ const char** name_result) {
tm decomposed;
bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
- ASSERT(succeeded);
- // Even if the offset was 24 hours it would still easily fit into 32 bits.
- return static_cast<int>(decomposed.tm_gmtoff);
+ if (!succeeded) return false;
+ *name_result = decomposed.tm_zone;
+ return true;
}
-int OS::GetLocalTimeZoneAdjustmentInSeconds() {
- // TODO(floitsch): avoid excessive calls to tzset?
- tzset();
+bool OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch,
+ int* offset_result) {
+ tm decomposed;
+ bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
+ if (!succeeded) return false;
// Even if the offset was 24 hours it would still easily fit into 32 bits.
- // Note that Unix and Dart disagree on the sign.
- return static_cast<int>(-timezone);
+ *offset_result = static_cast<int>(decomposed.tm_gmtoff);
+ return true;
}
« 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