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

Unified Diff: runtime/vm/os_linux.cc

Issue 10536114: 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.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 e89b68f914b1262117fdb8c0f7026a0d816f1fd4..ff857cbe3519b799f551b6bb69bccfd665247a54 100644
--- a/runtime/vm/os_linux.cc
+++ b/runtime/vm/os_linux.cc
@@ -17,7 +17,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);
@@ -25,29 +33,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.h ('k') | runtime/vm/os_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698