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

Unified Diff: sdk/lib/core/duration.dart

Issue 12221087: Add +, - and * to Duration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comparison operators to Duration. Created 7 years, 10 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 | « no previous file | tests/corelib/duration_test.dart » ('j') | tests/corelib/duration_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/duration.dart
diff --git a/sdk/lib/core/duration.dart b/sdk/lib/core/duration.dart
index d68c9e73789cfd6df13426a583a5d07d74bbb9eb..015484053b66e53cb405b37339a68721ad08f2dd 100644
--- a/sdk/lib/core/duration.dart
+++ b/sdk/lib/core/duration.dart
@@ -50,6 +50,39 @@ class Duration implements Comparable {
milliseconds;
/**
+ * Returns the sum of this [Duration] and [other] as a new [Duration].
+ */
+ Duration operator +(Duration other) {
+ return new Duration(milliseconds: inMilliseconds + other.inMilliseconds);
+ }
+
+ /**
+ * Returns the difference of this [Duration] and [other] as a new
+ * [Duration].
+ */
+ Duration operator -(Duration other) {
+ return new Duration(milliseconds: inMilliseconds - other.inMilliseconds);
+ }
+
+ /**
+ * Multiplies this [Duration] by the given [factor] and returns the result
+ * as a new [Duration].
+ */
+ Duration operator *(int factor) {
+ return new Duration(milliseconds: inMilliseconds * factor);
+ }
Lasse Reichstein Nielsen 2013/02/09 01:13:30 Consider having ~/ too.
floitsch 2013/02/09 02:08:04 Done.
+
+ bool operator <(Duration other) => this.inMilliseconds < other.inMilliseconds;
+
+ bool operator >(Duration other) => this.inMilliseconds > other.inMilliseconds;
+
+ bool operator <=(Duration other) =>
+ this.inMilliseconds <= other.inMilliseconds;
+
+ bool operator >=(Duration other) =>
+ this.inMilliseconds >= other.inMilliseconds;
+
+ /**
* This [Duration] in days. Incomplete days are discarded
*/
int get inDays {
« no previous file with comments | « no previous file | tests/corelib/duration_test.dart » ('j') | tests/corelib/duration_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698