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

Unified Diff: runtime/vm/os_win.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_macos.cc ('k') | samples/total/client/DateTimeUtils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_win.cc
diff --git a/runtime/vm/os_win.cc b/runtime/vm/os_win.cc
index e0ff669ea715d19b74e184e224409386854021e3..778f9953d8c7bb7c11587b0a3d2761107dc19d30 100644
--- a/runtime/vm/os_win.cc
+++ b/runtime/vm/os_win.cc
@@ -10,8 +10,16 @@
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;
+ errno_t error_code = gmtime_s(tm_result, &seconds);
+ return error_code == 0;
+}
+
+
// As a side-effect sets the globals _timezone, _daylight and _tzname.
-static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
+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;
// localtime_s implicitly sets _timezone, _daylight and _tzname.
@@ -20,6 +28,34 @@ static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
}
+bool OS::MkGmTime(tm* tm, int64_t* seconds_result) {
+ // Disable daylight saving.
+ tm->tm_isdst = 0;
+ // Set wday to an impossible day, so that we can catch bad input.
+ tm->tm_wday = -1;
+ time_t seconds = _mkgmtime(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;
+}
+
+
static int GetDaylightSavingBiasInSeconds() {
TIME_ZONE_INFORMATION zone_information;
memset(&zone_information, 0, sizeof(zone_information));
@@ -31,41 +67,39 @@ static int GetDaylightSavingBiasInSeconds() {
}
}
-
-const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) {
+bool OS::GetTimeZoneName(int64_t seconds_since_epoch,
+ const char** name_result) {
tm decomposed;
// LocalTime will set _tzname.
bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
- ASSERT(succeeded);
+ if (!succeeded) return false;
int inDaylightSavingsTime = decomposed.tm_isdst;
- ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1);
- return _tzname[inDaylightSavingsTime];
+ if (inDaylightSavingsTime != 0 && inDaylightSavingsTime != 1) {
+ return false;
+ }
+ *name_result = _tzname[inDaylightSavingsTime];
+ return true;
}
-int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) {
+bool OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch,
+ int* offset_result) {
tm decomposed;
// LocalTime will set _timezone.
bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
- ASSERT(succeeded);
+ if (!succeeded) return false;
int inDaylightSavingsTime = decomposed.tm_isdst;
- ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1);
+ if (inDaylightSavingsTime != 0 && inDaylightSavingsTime != 1) {
+ return false;
+ }
// Dart and Windows disagree on the sign of the bias.
- int offset = static_cast<int>(-_timezone);
+ *offset_result = static_cast<int>(-_timezone);
if (inDaylightSavingsTime == 1) {
static int daylight_bias = GetDaylightSavingBiasInSeconds();
// Subtract because windows and Dart disagree on the sign.
- offset = offset - daylight_bias;
+ *offset_result = *offset_result - daylight_bias;
}
- return offset;
-}
-
-
-int OS::GetLocalTimeZoneAdjustmentInSeconds() {
- // TODO(floitsch): avoid excessive calls to _tzset?
- _tzset();
- // Dart and Windows disagree on the sign of the bias.
- return static_cast<int>(-_timezone);
+ return true;
}
« no previous file with comments | « runtime/vm/os_macos.cc ('k') | samples/total/client/DateTimeUtils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698