Index: sdk/lib/io/timer_impl.dart |
diff --git a/sdk/lib/io/timer_impl.dart b/sdk/lib/io/timer_impl.dart |
index a3eb9529a360a177f4e13de35d6f599afc4a1095..883d09e42488bbefb6614636d2d12a9e363f82c4 100644 |
--- a/sdk/lib/io/timer_impl.dart |
+++ b/sdk/lib/io/timer_impl.dart |
@@ -24,8 +24,12 @@ class _Timer extends LinkedListEntry<_Timer> implements Timer { |
_Timer timer = new _Timer._internal(); |
timer._callback = callback; |
if (milliSeconds > 0) { |
+ // Add one because DateTime.now() is assumed to round down |
+ // to nearest millisecond, not up, so that time + duration is before |
+ // duration milliseconds from now. Using micosecond timers like |
+ // Stopwatch allows detecting that the timer fires early. |
timer._wakeupTime = |
- new DateTime.now().millisecondsSinceEpoch + milliSeconds; |
+ new DateTime.now().millisecondsSinceEpoch + 1 + milliSeconds; |
} |
timer._milliSeconds = repeating ? milliSeconds : -1; |
timer._addTimerToList(); |