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

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

Issue 12221094: Deprecate comparison operators of DateTime. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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/co19/co19-dart2dart.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/date_time.dart
diff --git a/sdk/lib/core/date_time.dart b/sdk/lib/core/date_time.dart
index cbeeccd6abacf97baf4a416e275bcbf564ebfd48..b57b63024b339c5138397e0160272fe777e1f07e 100644
--- a/sdk/lib/core/date_time.dart
+++ b/sdk/lib/core/date_time.dart
@@ -272,45 +272,84 @@ class DateTime implements Date {
}
/**
- * Returns true if [this] occurs at the same time as [other]. The
- * comparison is independent of whether the time is utc or in the local
- * time zone.
+ * Returns true if [other] is a [DateTime] at the same moment and in the
+ * same timezone (UTC or local).
+ *
+ * See [isAtSameMomentAs] for a comparison that ignores the timezone.
*/
bool operator ==(other) {
if (!(other is DateTime)) return false;
- return (millisecondsSinceEpoch == other.millisecondsSinceEpoch);
+ return (millisecondsSinceEpoch == other.millisecondsSinceEpoch &&
+ isUtc == other.isUtc);
}
/**
* Returns true if [this] occurs before [other]. The comparison is independent
- * of whether the time is utc or in the local time zone.
+ * of whether the time is in UTC or in the local time zone.
+ *
+ * *Deprecated* Use [isBefore] instead.
*/
+ @deprecated
bool operator <(DateTime other)
=> millisecondsSinceEpoch < other.millisecondsSinceEpoch;
/**
* Returns true if [this] occurs at the same time or before [other]. The
- * comparison is independent of whether the time is utc or in the local
+ * comparison is independent of whether the time is in UTC or in the local
* time zone.
+ *
+ * *Deprecated* Use [isAfter] instead ([:!isAfter:]).
*/
+ @deprecated
bool operator <=(DateTime other)
=> millisecondsSinceEpoch <= other.millisecondsSinceEpoch;
/**
* Returns true if [this] occurs after [other]. The comparison is independent
- * of whether the time is utc or in the local time zone.
+ * of whether the time is in UTC or in the local time zone.
+ *
+ * *Deprecated* Use [isAfter] instead.
*/
+ @deprecated
bool operator >(DateTime other)
=> millisecondsSinceEpoch > other.millisecondsSinceEpoch;
/**
* Returns true if [this] occurs at the same time or after [other]. The
- * comparison is independent of whether the time is utc or in the local
+ * comparison is independent of whether the time is in UTC or in the local
* time zone.
+ *
+ * *Deprecated* Use [isBefore] instead ([:!isBefore:]).
*/
+ @deprecated
bool operator >=(DateTime other)
=> millisecondsSinceEpoch >= other.millisecondsSinceEpoch;
+ /**
+ * Returns true if [this] occurs before [other]. The comparison is independent
+ * of whether the time is in UTC or in the local time zone.
+ */
+ bool isBefore(DateTime other) {
+ return millisecondsSinceEpoch < other.millisecondsSinceEpoch;
+ }
+
+ /**
+ * Returns true if [this] occurs after [other]. The comparison is independent
+ * of whether the time is in UTC or in the local time zone.
+ */
+ bool isAfter(DateTime other) {
+ return millisecondsSinceEpoch > other.millisecondsSinceEpoch;
+ }
+
+ /**
+ * Returns true if [this] occurs at the same moment as [other]. The
+ * comparison is independent of whether the time is in UTC or in the local
+ * time zone.
+ */
+ bool isAtSameMomentAs(DateTime other) {
+ return millisecondsSinceEpoch == other.millisecondsSinceEpoch;
+ }
+
int compareTo(DateTime other)
=> millisecondsSinceEpoch.compareTo(other.millisecondsSinceEpoch);
« no previous file with comments | « no previous file | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698