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

Unified Diff: runtime/vm/os_linux.cc

Issue 10536116: Reapply "Refactor Date implementation in VM." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. 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.h ('k') | runtime/vm/os_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_linux.cc
diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc
index ff857cbe3519b799f551b6bb69bccfd665247a54..e89b68f914b1262117fdb8c0f7026a0d816f1fd4 100644
--- a/runtime/vm/os_linux.cc
+++ b/runtime/vm/os_linux.cc
@@ -17,15 +17,7 @@
namespace dart {
-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) {
+static bool 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);
@@ -33,50 +25,29 @@ bool OS::LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
}
-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;
+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::GetTimeZoneName(int64_t seconds_since_epoch,
- const char** name_result) {
+int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) {
tm decomposed;
bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
- if (!succeeded) return false;
- *name_result = decomposed.tm_zone;
- return true;
+ ASSERT(succeeded);
+ // Even if the offset was 24 hours it would still easily fit into 32 bits.
+ return static_cast<int>(decomposed.tm_gmtoff);
}
-bool OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch,
- int* offset_result) {
- tm decomposed;
- bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
- if (!succeeded) return false;
+int OS::GetLocalTimeZoneAdjustmentInSeconds() {
+ // TODO(floitsch): avoid excessive calls to tzset?
+ tzset();
// Even if the offset was 24 hours it would still easily fit into 32 bits.
- *offset_result = static_cast<int>(decomposed.tm_gmtoff);
- return true;
+ // Note that Unix and Dart disagree on the sign.
+ return static_cast<int>(-timezone);
}
« no previous file with comments | « runtime/vm/os.h ('k') | runtime/vm/os_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698