Index: sdk/lib/core/date.dart |
diff --git a/sdk/lib/core/date.dart b/sdk/lib/core/date.dart |
index d0c0f01d26819194ae0dcc130f6afaa7fe4f96b5..11e010ba69a9a0e5d027f4991bf9905134403ab0 100644 |
--- a/sdk/lib/core/date.dart |
+++ b/sdk/lib/core/date.dart |
@@ -13,7 +13,7 @@ part of dart.core; |
* |
* Also see [Stopwatch] for means to measure time-spans. |
*/ |
-abstract class Date implements Comparable { |
+abstract class DateTime implements Comparable { |
Lasse Reichstein Nielsen
2013/01/09 16:09:29
Begin rant:
I still think it's a bad name. It's no
|
// Weekday constants that are returned by [weekday] method: |
static const int MON = 1; |
static const int TUE = 2; |
@@ -39,13 +39,13 @@ abstract class Date implements Comparable { |
static const int DEC = 12; |
/** |
- * Constructs a [Date] instance based on the individual parts. The date is |
+ * Constructs a [DateTime] instance based on the individual parts. The date is |
* in the local time zone. |
* |
* [month] and [day] are one-based. For example |
- * [:new Date(1938, 1, 10):] represents the 10th of January 1938. |
+ * [:new DateTime(1938, 1, 10):] represents the 10th of January 1938. |
*/ |
- factory Date(int year, |
+ factory DateTime(int year, |
[int month = 1, |
int day = 1, |
int hour = 0, |
@@ -57,14 +57,14 @@ abstract class Date implements Comparable { |
} |
/** |
- * Constructs a [Date] instance based on the individual parts. The date is |
+ * Constructs a [DateTime] instance based on the individual parts. The date is |
* in the UTC time zone. |
* |
* [month] and [day] are one-based. For example |
- * [:new Date.utc(1938, 1, 10):] represents the 10th of January 1938 in |
+ * [:new DateTime.utc(1938, 1, 10):] represents the 10th of January 1938 in |
* Coordinated Universal Time. |
*/ |
- factory Date.utc(int year, |
+ factory DateTime.utc(int year, |
[int month = 1, |
int day = 1, |
int hour = 0, |
@@ -76,29 +76,29 @@ abstract class Date implements Comparable { |
} |
/** |
- * Constructs a new [Date] instance with current date time value in the |
+ * Constructs a new [DateTime] instance with current date time value in the |
* local time zone. |
*/ |
- factory Date.now() => new _DateImpl.now(); |
+ factory DateTime.now() => new _DateImpl.now(); |
/** |
- * Constructs a new [Date] instance based on [formattedString]. |
+ * Constructs a new [DateTime] instance based on [formattedString]. |
*/ |
- factory Date.fromString(String formattedString) |
+ factory DateTime.fromString(String formattedString) |
=> new _DateImpl.fromString(formattedString); |
/** |
- * Constructs a new [Date] instance with the given [millisecondsSinceEpoch]. |
+ * Constructs a new [DateTime] instance with the given [millisecondsSinceEpoch]. |
* If [isUtc] is false then the date is in the local time zone. |
* |
- * The constructed [Date] represents |
+ * The constructed [DateTime] represents |
* 1970-01-01T00:00:00Z + [millisecondsSinceEpoch]ms in the given |
* time zone (local or UTC). |
*/ |
// TODO(floitsch): the spec allows default values in interfaces, but our |
// tools don't yet. Eventually we want to have default values here. |
Lasse Reichstein Nielsen
2013/01/09 16:09:29
Comment out-dated? We have a default value in the
floitsch
2013/01/22 20:23:39
Done.
|
// TODO(lrn): Have two constructors instead of taking an optional bool. |
- factory Date.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, |
+ factory DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, |
{bool isUtc: false}) { |
return new _DateImpl.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
isUtc); |
@@ -109,46 +109,46 @@ abstract class Date implements Comparable { |
* comparison is independent of whether the time is utc or in the local |
* time zone. |
*/ |
- bool operator ==(Date other); |
+ bool operator ==(DateTime other); |
/** |
* Returns true if [this] occurs before [other]. The comparison is independent |
* of whether the time is utc or in the local time zone. |
*/ |
- bool operator <(Date other); |
+ bool operator <(DateTime other); |
/** |
* 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 |
* time zone. |
*/ |
- bool operator <=(Date other); |
+ bool operator <=(DateTime other); |
/** |
* Returns true if [this] occurs after [other]. The comparison is independent |
* of whether the time is utc or in the local time zone. |
*/ |
- bool operator >(Date other); |
+ bool operator >(DateTime other); |
/** |
* 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 |
* time zone. |
*/ |
- bool operator >=(Date other); |
+ bool operator >=(DateTime other); |
/** |
* Returns [this] in the local time zone. Returns itself if it is already in |
* the local time zone. Otherwise, this method is equivalent to |
- * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
+ * [:new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
* isUtc: false):]. |
*/ |
- Date toLocal(); |
+ DateTime toLocal(); |
/** |
* Returns [this] in UTC. Returns itself if it is already in UTC. Otherwise, |
* this method is equivalent to |
- * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
+ * [:new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
* isUtc: true):]. |
*/ |
- Date toUtc(); |
+ DateTime toUtc(); |
/** |
* Returns the abbreviated time-zone name. |
@@ -217,7 +217,7 @@ abstract class Date implements Comparable { |
int get millisecondsSinceEpoch; |
/** |
- * True if this [Date] is set to UTC time. |
+ * True if this [DateTime] is set to UTC time. |
*/ |
bool get isUtc; |
@@ -228,22 +228,22 @@ abstract class Date implements Comparable { |
String toString(); |
/** |
- * Returns a new [Date] with the [duration] added to this instance. |
+ * Returns a new [DateTime] with the [duration] added to this instance. |
*/ |
- Date add(Duration duration); |
+ DateTime add(Duration duration); |
/** |
- * Returns a new [Date] with the [duration] subtracted from this instance. |
+ * Returns a new [DateTime] with the [duration] subtracted from this instance. |
*/ |
- Date subtract(Duration duration); |
+ DateTime subtract(Duration duration); |
/** |
* Returns a [Duration] with the difference of [:this:] and [other]. |
*/ |
- Duration difference(Date other); |
+ Duration difference(DateTime other); |
} |
-class _DateImpl implements Date { |
+class _DateImpl implements DateTime { |
final int millisecondsSinceEpoch; |
final bool isUtc; |
@@ -294,7 +294,7 @@ class _DateImpl implements Date { |
throw new ArgumentError(formattedString); |
} |
if (addOneMillisecond) millisecondsSinceEpoch++; |
- return new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
+ return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
isUtc: isUtc); |
} else { |
throw new ArgumentError(formattedString); |
@@ -312,38 +312,38 @@ class _DateImpl implements Date { |
} |
bool operator ==(other) { |
- if (!(other is Date)) return false; |
+ if (!(other is DateTime)) return false; |
return (millisecondsSinceEpoch == other.millisecondsSinceEpoch); |
} |
- bool operator <(Date other) |
+ bool operator <(DateTime other) |
=> millisecondsSinceEpoch < other.millisecondsSinceEpoch; |
- bool operator <=(Date other) |
+ bool operator <=(DateTime other) |
=> millisecondsSinceEpoch <= other.millisecondsSinceEpoch; |
- bool operator >(Date other) |
+ bool operator >(DateTime other) |
=> millisecondsSinceEpoch > other.millisecondsSinceEpoch; |
- bool operator >=(Date other) |
+ bool operator >=(DateTime other) |
=> millisecondsSinceEpoch >= other.millisecondsSinceEpoch; |
- int compareTo(Date other) |
+ int compareTo(DateTime other) |
=> millisecondsSinceEpoch.compareTo(other.millisecondsSinceEpoch); |
int get hashCode => millisecondsSinceEpoch; |
- Date toLocal() { |
+ DateTime toLocal() { |
if (isUtc) { |
- return new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
+ return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
isUtc: false); |
} |
return this; |
} |
- Date toUtc() { |
+ DateTime toUtc() { |
if (isUtc) return this; |
- return new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
+ return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
isUtc: true); |
} |
@@ -382,22 +382,22 @@ class _DateImpl implements Date { |
} |
} |
- /** Returns a new [Date] with the [duration] added to [this]. */ |
- Date add(Duration duration) { |
+ /** Returns a new [DateTime] with the [duration] added to [this]. */ |
+ DateTime add(Duration duration) { |
int ms = millisecondsSinceEpoch; |
- return new Date.fromMillisecondsSinceEpoch( |
+ return new DateTime.fromMillisecondsSinceEpoch( |
ms + duration.inMilliseconds, isUtc: isUtc); |
} |
- /** Returns a new [Date] with the [duration] subtracted from [this]. */ |
- Date subtract(Duration duration) { |
+ /** Returns a new [DateTime] with the [duration] subtracted from [this]. */ |
+ DateTime subtract(Duration duration) { |
int ms = millisecondsSinceEpoch; |
- return new Date.fromMillisecondsSinceEpoch( |
+ return new DateTime.fromMillisecondsSinceEpoch( |
ms - duration.inMilliseconds, isUtc: isUtc); |
} |
/** Returns a [Duration] with the difference of [this] and [other]. */ |
- Duration difference(Date other) { |
+ Duration difference(DateTime other) { |
int ms = millisecondsSinceEpoch; |
int otherMs = other.millisecondsSinceEpoch; |
return new Duration(milliseconds: ms - otherMs); |