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

Unified Diff: tests/corelib/date_time_test.dart

Issue 1493033003: Add microsecond support to DateTime. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comment. Created 5 years 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 | « tests/corelib/date_time_parse_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/date_time_test.dart
diff --git a/tests/corelib/date_time_test.dart b/tests/corelib/date_time_test.dart
index 79dcdd95b14607540db79b9eb8e10e6b5a11bd6f..7895598f268d52b7ae476db13876d8d36ea67582 100644
--- a/tests/corelib/date_time_test.dart
+++ b/tests/corelib/date_time_test.dart
@@ -6,6 +6,9 @@ import "package:expect/expect.dart";
// Dart test program for DateTime.
+bool get supportsMicroseconds =>
+ new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1;
+
// Identical to _MAX_MILLISECONDS_SINCE_EPOCH in date_time.dart
const int _MAX_MILLISECONDS = 8640000000000000;
@@ -26,13 +29,26 @@ void testNow() {
Expect.isFalse(t1.isUtc);
}
-void testValue() {
+void testMillisecondsSinceEpoch() {
var dt1 = new DateTime.now();
var millisecondsSinceEpoch = dt1.millisecondsSinceEpoch;
var dt2 = new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch);
Expect.equals(millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
}
+void testMicrosecondsSinceEpoch() {
+ var dt1 = new DateTime.fromMillisecondsSinceEpoch(1);
+ var microsecondsSinceEpoch = dt1.millisecondsSinceEpoch;
+ var dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch);
+ Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch);
+
+ if (!supportsMicroseconds) return;
+ dt1 = new DateTime.now();
+ microsecondsSinceEpoch = dt1.millisecondsSinceEpoch;
+ dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch);
+ Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch);
+}
+
void testFarAwayDates() {
DateTime dt =
new DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true);
@@ -43,6 +59,7 @@ void testFarAwayDates() {
Expect.equals(46, dt.minute);
Expect.equals(40, dt.second);
Expect.equals(1, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-1000000000000001, isUtc: true);
Expect.equals(-29719, dt.year);
Expect.equals(4, dt.month);
@@ -51,6 +68,7 @@ void testFarAwayDates() {
Expect.equals(13, dt.minute);
Expect.equals(19, dt.second);
Expect.equals(999, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
// Same with local zone.
dt = new DateTime.fromMillisecondsSinceEpoch(1000000000000001);
Expect.equals(33658, dt.year);
@@ -62,6 +80,7 @@ void testFarAwayDates() {
Expect.equals(true, dt.minute % 15 == 46 % 15);
Expect.equals(40, dt.second);
Expect.equals(1, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-1000000000000001);
Expect.equals(-29719, dt.year);
Expect.equals(4, dt.month);
@@ -72,6 +91,52 @@ void testFarAwayDates() {
Expect.equals(true, dt.minute % 15 == 13);
Expect.equals(19, dt.second);
Expect.equals(999, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
+
+ if (!supportsMicroseconds) return;
+ dt =
+ new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001, isUtc: true);
+ Expect.equals(33658, dt.year);
+ Expect.equals(9, dt.month);
+ Expect.equals(27, dt.day);
+ Expect.equals(1, dt.hour);
+ Expect.equals(46, dt.minute);
+ Expect.equals(40, dt.second);
+ Expect.equals(0, dt.millisecond);
+ Expect.equals(1, dt.microsecond);
+ dt = new DateTime.fromMicrosecondsSinceEpoch(
+ -1000000000000000001, isUtc: true);
+ Expect.equals(-29719, dt.year);
+ Expect.equals(4, dt.month);
+ Expect.equals(5, dt.day);
+ Expect.equals(22, dt.hour);
+ Expect.equals(13, dt.minute);
+ Expect.equals(19, dt.second);
+ Expect.equals(999, dt.millisecond);
+ Expect.equals(999, dt.microsecond);
+ // Same with local zone.
+ dt = new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001);
+ Expect.equals(33658, dt.year);
+ Expect.equals(9, dt.month);
+ Expect.equals(true, dt.day == 27 || dt.day == 26);
+ // Not much we can test for local hour.
+ Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
+ // Timezones can have offsets down to 15 minute.
+ Expect.equals(true, dt.minute % 15 == 46 % 15);
+ Expect.equals(40, dt.second);
+ Expect.equals(0, dt.millisecond);
+ Expect.equals(1, dt.microsecond);
+ dt = new DateTime.fromMicrosecondsSinceEpoch(-1000000000000000001);
+ Expect.equals(-29719, dt.year);
+ Expect.equals(4, dt.month);
+ Expect.equals(true, 5 == dt.day || 6 == dt.day);
+ // Not much we can test for local hour.
+ Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
+ // Timezones can have offsets down to 15 minute.
+ Expect.equals(true, dt.minute % 15 == 13);
+ Expect.equals(19, dt.second);
+ Expect.equals(999, dt.millisecond);
+ Expect.equals(999, dt.microsecond);
}
void testEquivalentYears() {
@@ -86,6 +151,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-63108000000, isUtc: true);
Expect.equals(1968, dt.year);
Expect.equals(1, dt.month);
@@ -94,6 +160,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-94644000000, isUtc: true);
Expect.equals(1967, dt.year);
Expect.equals(1, dt.month);
@@ -102,6 +169,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-126180000000, isUtc: true);
Expect.equals(1966, dt.year);
Expect.equals(1, dt.month);
@@ -110,6 +178,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-157716000000, isUtc: true);
Expect.equals(1965, dt.year);
Expect.equals(1, dt.month);
@@ -118,6 +187,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-2177402400000, isUtc: true);
Expect.equals(1901, dt.year);
Expect.equals(1, dt.month);
@@ -126,6 +196,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-5333076000000, isUtc: true);
Expect.equals(1801, dt.year);
Expect.equals(1, dt.month);
@@ -134,6 +205,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-8520285600000, isUtc: true);
Expect.equals(1700, dt.year);
Expect.equals(1, dt.month);
@@ -142,6 +214,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-14831719200000, isUtc: true);
Expect.equals(1500, dt.year);
Expect.equals(1, dt.month);
@@ -150,6 +223,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-59011408800000, isUtc: true);
Expect.equals(100, dt.year);
Expect.equals(1, dt.month);
@@ -158,6 +232,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-62011408800000, isUtc: true);
Expect.equals(4, dt.year);
Expect.equals(12, dt.month);
@@ -166,6 +241,7 @@ void testEquivalentYears() {
Expect.equals(40, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-64011408800000, isUtc: true);
Expect.equals(-59, dt.year);
Expect.equals(7, dt.month);
@@ -174,6 +250,7 @@ void testEquivalentYears() {
Expect.equals(6, dt.minute);
Expect.equals(40, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
final int SECONDS_YEAR_2035 = 2051222400;
dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 + 1,
isUtc: true);
@@ -184,6 +261,7 @@ void testEquivalentYears() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(1, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 - 1,
isUtc: true);
Expect.equals(2034, dt.year);
@@ -193,6 +271,8 @@ void testEquivalentYears() {
Expect.equals(59, dt.minute);
Expect.equals(59, dt.second);
Expect.equals(999, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
+
dt = new DateTime.utc(2035, 1, 1, 0, 0, 0, 1);
Expect.equals(SECONDS_YEAR_2035 * 1000 + 1, dt.millisecondsSinceEpoch);
dt = new DateTime.utc(2034, 12, 31, 23, 59, 59, 999);
@@ -211,6 +291,8 @@ void testEquivalentYears() {
(2034 == dt.year && 12 == dt.month && 31 == dt.day));
Expect.equals(59, dt.second);
Expect.equals(999, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
+
dt2 = new DateTime(
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
dt.millisecond);
@@ -223,6 +305,8 @@ void testEquivalentYears() {
Expect.equals(20, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
+
// Internally this will use the maximum value for the native calls.
dt = new DateTime(2036, 7, 18, 13, 20);
Expect.equals(2036, dt.year);
@@ -232,7 +316,46 @@ void testEquivalentYears() {
Expect.equals(20, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
Expect.equals("2036-07-18 13:20:00.000", dt.toString());
+
+ if (!supportsMicroseconds) return;
+
+ dt = new DateTime.utc(2035, 1, 1, 0, 0, 0, 0, 1);
+ Expect.equals(SECONDS_YEAR_2035 * 1000000 + 1, dt.microsecondsSinceEpoch);
+ dt = new DateTime.utc(2034, 12, 31, 23, 59, 59, 999, 999);
+ Expect.equals(SECONDS_YEAR_2035 * 1000000 - 1, dt.microsecondsSinceEpoch);
+ dt = new DateTime.fromMicrosecondsSinceEpoch(SECONDS_YEAR_2035 * 1000000 + 1);
+ Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
+ (2034 == dt.year && 12 == dt.month && 31 == dt.day));
+ Expect.equals(0, dt.second);
+ Expect.equals(0, dt.millisecond);
+ Expect.equals(1, dt.microsecond);
+ dt2 = new DateTime(
+ dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
+ dt.millisecond, dt.microsecond);
+ Expect.equals(dt.microsecondsSinceEpoch, dt2.microsecondsSinceEpoch);
+ dt = new DateTime.fromMicrosecondsSinceEpoch(SECONDS_YEAR_2035 * 1000000 - 1);
+ Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
+ (2034 == dt.year && 12 == dt.month && 31 == dt.day));
+ Expect.equals(59, dt.second);
+ Expect.equals(999, dt.millisecond);
+ Expect.equals(999, dt.microsecond);
+
+ dt2 = new DateTime(
+ dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
+ dt.millisecond, dt.microsecond);
+ Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
+ dt = new DateTime.fromMicrosecondsSinceEpoch(2100000000 * 1000000,
+ isUtc: true);
+ Expect.equals(2036, dt.year);
+ Expect.equals(7, dt.month);
+ Expect.equals(18, dt.day);
+ Expect.equals(13, dt.hour);
+ Expect.equals(20, dt.minute);
+ Expect.equals(0, dt.second);
+ Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
}
void testExtremes() {
@@ -245,6 +368,7 @@ void testExtremes() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
Expect.equals(-271821, dt.year);
Expect.equals(4, dt.month);
@@ -253,6 +377,7 @@ void testExtremes() {
Expect.equals(0, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
// Make sure that we can build the extreme dates in local too.
dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
@@ -280,6 +405,35 @@ void testExtremes() {
dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
Expect.throws(() => new DateTime.utc(dt.year, dt.month, dt.day,
dt.hour, dt.minute, 0, -1));
+
+ if (!supportsMicroseconds) return;
+
+ dt = new DateTime.fromMicrosecondsSinceEpoch(_MAX_MILLISECONDS * 1000);
+ dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
+ Expect.equals(_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch);
+ dt = new DateTime.fromMicrosecondsSinceEpoch(-_MAX_MILLISECONDS * 1000);
+ dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
+ Expect.equals(-_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch);
+ Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
+ _MAX_MILLISECONDS * 1000 + 1, isUtc: true));
+ Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
+ -_MAX_MILLISECONDS * 1000 - 1, isUtc: true));
+ Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
+ _MAX_MILLISECONDS * 1000 + 1));
+ Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
+ -_MAX_MILLISECONDS * 1000 - 1));
+ dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
+ Expect.throws(() => new DateTime(dt.year, dt.month, dt.day,
+ dt.hour, dt.minute, 0, 0, 1));
+ dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
+ Expect.throws(() => new DateTime.utc(dt.year, dt.month, dt.day,
+ dt.hour, dt.minute, 0, 0, 1));
+ dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
+ Expect.throws(() => new DateTime(dt.year, dt.month, dt.day,
+ dt.hour, dt.minute, 0, 0, -1));
+ dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
+ Expect.throws(() => new DateTime.utc(dt.year, dt.month, dt.day,
+ dt.hour, dt.minute, 0, 0, -1));
}
void testUTCGetters() {
@@ -291,6 +445,7 @@ void testUTCGetters() {
Expect.equals(58, dt.minute);
Expect.equals(35, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
Expect.equals(true, dt.isUtc);
Expect.equals(1305140315000, dt.millisecondsSinceEpoch);
dt = new DateTime.fromMillisecondsSinceEpoch(-9999999, isUtc: true);
@@ -301,12 +456,26 @@ void testUTCGetters() {
Expect.equals(13, dt.minute);
Expect.equals(20, dt.second);
Expect.equals(1, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
+
+ if (!supportsMicroseconds) return;
+
+ dt = new DateTime.fromMicrosecondsSinceEpoch(-9999999999, isUtc: true);
+ Expect.equals(1969, dt.year);
+ Expect.equals(12, dt.month);
+ Expect.equals(31, dt.day);
+ Expect.equals(21, dt.hour);
+ Expect.equals(13, dt.minute);
+ Expect.equals(20, dt.second);
+ Expect.equals(0, dt.millisecond);
+ Expect.equals(1, dt.microsecond);
}
void testLocalGetters() {
var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000);
var dt2 = new DateTime.utc(dt1.year, dt1.month, dt1.day,
- dt1.hour, dt1.minute, dt1.second, dt1.millisecond);
+ dt1.hour, dt1.minute, dt1.second, dt1.millisecond,
+ dt1.microsecond);
Duration zoneOffset = dt1.difference(dt2);
Expect.equals(true, zoneOffset.inDays == 0);
Expect.equals(true, zoneOffset.inHours.abs() <= 12);
@@ -321,34 +490,40 @@ void testLocalGetters() {
((dt1.minute - dt2.minute).abs() == 15));
Expect.equals(dt1.second, dt2.second);
Expect.equals(dt1.millisecond, dt2.millisecond);
+ Expect.equals(dt1.microsecond, dt2.microsecond);
}
void testConstructors() {
- var dt0 = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0);
- var dt0b = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0).toLocal();
+ var dt0 = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0, 0);
+ var dt0b = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0, 0).toLocal();
Expect.equals(1305140315000, dt0.millisecondsSinceEpoch);
var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000);
Expect.equals(dt1.millisecondsSinceEpoch, dt0.millisecondsSinceEpoch);
+ Expect.equals(dt1.microsecondsSinceEpoch, dt0.microsecondsSinceEpoch);
Expect.equals(false, dt1 == dt0);
Expect.equals(true, dt1 == dt0b);
var dt3 = new DateTime(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
- dt1.second, dt1.millisecond);
+ dt1.second, dt1.millisecond, dt1.microsecond);
Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
+ Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
Expect.equals(false, dt3 == dt0);
Expect.equals(true, dt1 == dt3);
dt3 = new DateTime(
dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
- dt1.second, dt1.millisecond);
+ dt1.second, dt1.millisecond, dt1.microsecond);
Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
+ Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
Expect.equals(true, dt1 == dt3);
var dt2 = dt1.toLocal();
- dt3 = new DateTime(2011, 5, dt1.day, dt1.hour, dt1.minute, 35, 0);
+ dt3 = new DateTime(2011, 5, dt1.day, dt1.hour, dt1.minute, 35, 0, 0);
Expect.equals(dt2.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
+ Expect.equals(dt2.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
Expect.equals(true, dt2 == dt3);
dt1 = new DateTime.fromMillisecondsSinceEpoch(-9999999, isUtc: true);
dt3 = new DateTime.utc(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
dt1.second, dt1.millisecond);
Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
+ Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
dt3 = new DateTime.utc(99, 1, 2, 10, 11, 12, 0);
Expect.equals(99, dt3.year);
Expect.equals(1, dt3.month);
@@ -357,6 +532,7 @@ void testConstructors() {
Expect.equals(11, dt3.minute);
Expect.equals(12, dt3.second);
Expect.equals(0, dt3.millisecond);
+ Expect.equals(0, dt3.microsecond);
Expect.equals(true, dt3.isUtc);
var dt4 = new DateTime(99, 1, 2);
Expect.equals(99, dt4.year);
@@ -366,6 +542,7 @@ void testConstructors() {
Expect.equals(0, dt4.minute);
Expect.equals(0, dt4.second);
Expect.equals(0, dt4.millisecond);
+ Expect.equals(0, dt4.microsecond);
Expect.isFalse(dt4.isUtc);
var dt5 = new DateTime.utc(99, 1, 2);
Expect.equals(99, dt5.year);
@@ -375,6 +552,7 @@ void testConstructors() {
Expect.equals(0, dt5.minute);
Expect.equals(0, dt5.second);
Expect.equals(0, dt5.millisecond);
+ Expect.equals(0, dt5.microsecond);
Expect.isTrue(dt5.isUtc);
var dt6 = new DateTime(2012, 2, 27, 13, 27, 0);
Expect.equals(2012, dt6.year);
@@ -384,6 +562,7 @@ void testConstructors() {
Expect.equals(27, dt6.minute);
Expect.equals(0, dt6.second);
Expect.equals(0, dt6.millisecond);
+ Expect.equals(0, dt6.microsecond);
Expect.isFalse(dt6.isUtc);
var dt7 = new DateTime.utc(2012, 2, 27, 13, 27, 0);
Expect.equals(2012, dt7.year);
@@ -393,6 +572,7 @@ void testConstructors() {
Expect.equals(27, dt7.minute);
Expect.equals(0, dt7.second);
Expect.equals(0, dt7.millisecond);
+ Expect.equals(0, dt7.microsecond);
Expect.isTrue(dt7.isUtc);
}
@@ -409,6 +589,7 @@ void testChangeTimeZone() {
Expect.equals(dt2.minute, dt3.minute);
Expect.equals(dt2.second, dt3.second);
Expect.equals(dt2.millisecond, dt3.millisecond);
+ Expect.equals(dt2.microsecond, dt3.microsecond);
var dt4 = dt3.toLocal();
Expect.equals(dt1.year, dt4.year);
Expect.equals(dt1.month, dt4.month);
@@ -417,6 +598,7 @@ void testChangeTimeZone() {
Expect.equals(dt1.minute, dt4.minute);
Expect.equals(dt1.second, dt4.second);
Expect.equals(dt1.millisecond, dt4.millisecond);
+ Expect.equals(dt1.microsecond, dt4.microsecond);
}
void testSubAdd() {
@@ -430,19 +612,39 @@ void testSubAdd() {
Expect.equals(dt1.minute, dt2.minute);
Expect.equals(dt1.second + 3, dt2.second);
Expect.equals(dt1.millisecond + 5, dt2.millisecond);
+ Expect.equals(dt1.microsecond, dt2.microsecond);
var dt3 = dt2.subtract(new Duration(milliseconds:
3 * Duration.MILLISECONDS_PER_SECOND + 5));
Expect.equals(true, dt1 == dt3);
Expect.equals(false, dt1 == dt2);
+
+ if (!supportsMicroseconds) return;
+
+ dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
+ dt2 = dt1.add(new Duration(microseconds:
+ 3 * Duration.MICROSECONDS_PER_SECOND + 5));
+ Expect.equals(dt1.year, dt2.year);
+ Expect.equals(dt1.month, dt2.month);
+ Expect.equals(dt1.day, dt2.day);
+ Expect.equals(dt1.hour, dt2.hour);
+ Expect.equals(dt1.minute, dt2.minute);
+ Expect.equals(dt1.second + 3, dt2.second);
+ Expect.equals(dt1.millisecond, dt2.millisecond);
+ Expect.equals(dt1.microsecond + 5, dt2.microsecond);
+ dt3 = dt2.subtract(new Duration(microseconds:
+ 3 * Duration.MICROSECONDS_PER_SECOND + 5));
+ Expect.equals(true, dt1 == dt3);
+ Expect.equals(false, dt1 == dt2);
}
void testUnderflowAndOverflow() {
- final dtBase = new DateTime(2012, 6, 20, 12, 30, 30, 500);
+ int microsecond = supportsMicroseconds ? 499 : 0;
+ final dtBase = new DateTime(2012, 6, 20, 12, 30, 30, 500, microsecond);
// Millisecond
print(" >>> Millisecond+");
var dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
- dtBase.minute, dtBase.second, 1000);
+ dtBase.minute, dtBase.second, 1000, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month, dt.month);
Expect.equals(dtBase.day, dt.day);
@@ -450,10 +652,11 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute, dt.minute);
Expect.equals(dtBase.second + 1, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
print(" >>> Millisecond-");
dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
- dtBase.minute, dtBase.second, -1000);
+ dtBase.minute, dtBase.second, -1000, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month, dt.month);
Expect.equals(dtBase.day, dt.day);
@@ -461,11 +664,12 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute, dt.minute);
Expect.equals(dtBase.second - 1, dt.second);
Expect.equals(0, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
// Second
print(" >>> Second+");
dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
- dtBase.minute, 60, dtBase.millisecond);
+ dtBase.minute, 60, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month, dt.month);
Expect.equals(dtBase.day, dt.day);
@@ -473,10 +677,11 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute + 1, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
print(" >>> Second-");
dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
- dtBase.minute, -60, dtBase.millisecond);
+ dtBase.minute, -60, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month, dt.month);
Expect.equals(dtBase.day, dt.day);
@@ -484,11 +689,12 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute - 1, dt.minute);
Expect.equals(0, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
// Minute
print(" >>> Minute+");
dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 60,
- dtBase.second, dtBase.millisecond);
+ dtBase.second, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month, dt.month);
Expect.equals(dtBase.day, dt.day);
@@ -496,10 +702,11 @@ void testUnderflowAndOverflow() {
Expect.equals(0, dt.minute);
Expect.equals(dtBase.second, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
print(" >>> Minute-");
dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, -60,
- dtBase.second, dtBase.millisecond);
+ dtBase.second, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month, dt.month);
Expect.equals(dtBase.day, dt.day);
@@ -507,11 +714,12 @@ void testUnderflowAndOverflow() {
Expect.equals(0, dt.minute);
Expect.equals(dtBase.second, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
// Hour
print(" >>> Hour+");
dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, 24, dtBase.minute,
- dtBase.second, dtBase.millisecond);
+ dtBase.second, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month, dt.month);
Expect.equals(dtBase.day + 1, dt.day);
@@ -519,10 +727,11 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute, dt.minute);
Expect.equals(dtBase.second, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
print(" >>> Hour-");
dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, -24, dtBase.minute,
- dtBase.second, dtBase.millisecond);
+ dtBase.second, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month, dt.month);
Expect.equals(dtBase.day - 1, dt.day);
@@ -530,11 +739,12 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute, dt.minute);
Expect.equals(dtBase.second, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
// Day
print(" >>> Day+");
dt = new DateTime(dtBase.year, dtBase.month, 31, dtBase.hour, dtBase.minute,
- dtBase.second, dtBase.millisecond);
+ dtBase.second, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month + 1, dt.month);
Expect.equals(1, dt.day);
@@ -542,10 +752,11 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute, dt.minute);
Expect.equals(dtBase.second, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
print(" >>> Day-");
dt = new DateTime(dtBase.year, dtBase.month, -30, dtBase.hour, dtBase.minute,
- dtBase.second, dtBase.millisecond);
+ dtBase.second, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year, dt.year);
Expect.equals(dtBase.month - 1, dt.month);
Expect.equals(1, dt.day);
@@ -553,11 +764,12 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute, dt.minute);
Expect.equals(dtBase.second, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
// Month
print(" >>> Month+");
dt = new DateTime(dtBase.year, 13, dtBase.day, dtBase.hour, dtBase.minute,
- dtBase.second, dtBase.millisecond);
+ dtBase.second, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year + 1, dt.year);
Expect.equals(1, dt.month);
Expect.equals(dtBase.day, dt.day);
@@ -565,10 +777,11 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute, dt.minute);
Expect.equals(dtBase.second, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
print(" >>> Month-");
dt = new DateTime(dtBase.year, -11, dtBase.day, dtBase.hour, dtBase.minute,
- dtBase.second, dtBase.millisecond);
+ dtBase.second, dtBase.millisecond, dtBase.microsecond);
Expect.equals(dtBase.year - 1, dt.year);
Expect.equals(1, dt.month);
Expect.equals(dtBase.day, dt.day);
@@ -576,13 +789,14 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase.minute, dt.minute);
Expect.equals(dtBase.second, dt.second);
Expect.equals(dtBase.millisecond, dt.millisecond);
+ Expect.equals(dtBase.microsecond, dt.microsecond);
// Flowing all the way up the chain.
print(" >>> Flow+");
- var dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999);
+ var dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999, 000);
var dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day,
dtBase1.hour, dtBase1.minute, dtBase1.second,
- dtBase1.millisecond + 1);
+ dtBase1.millisecond + 1, dtBase1.microsecond);
Expect.equals(dtBase1.year + 1, dtTick.year);
Expect.equals(1, dtTick.month);
Expect.equals(1, dtTick.day);
@@ -590,11 +804,13 @@ void testUnderflowAndOverflow() {
Expect.equals(0, dtTick.minute);
Expect.equals(0, dtTick.second);
Expect.equals(0, dtTick.millisecond);
+ Expect.equals(0, dtTick.microsecond);
print(" >>> Flow-");
dtBase1 = new DateTime(2012, 1, 1, 0, 0, 0, 0);
dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, dtBase1.hour,
- dtBase1.minute, dtBase1.second, dtBase1.millisecond - 1);
+ dtBase1.minute, dtBase1.second, dtBase1.millisecond - 1,
+ dtBase1.microsecond);
Expect.equals(dtBase1.year - 1, dtTick.year);
Expect.equals(12, dtTick.month);
Expect.equals(31, dtTick.day);
@@ -602,10 +818,12 @@ void testUnderflowAndOverflow() {
Expect.equals(59, dtTick.minute);
Expect.equals(59, dtTick.second);
Expect.equals(999, dtTick.millisecond);
+ Expect.equals(0, dtTick.microsecond);
print(" >>> extra underflow");
dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, -17520,
- dtBase1.minute, dtBase1.second, dtBase1.millisecond);
+ dtBase1.minute, dtBase1.second, dtBase1.millisecond,
+ dtBase1.microsecond);
Expect.equals(dtBase1.year - 2, dtTick.year);
Expect.equals(dtBase1.month, dtTick.month);
Expect.equals(dtBase1.day, dtTick.day);
@@ -613,6 +831,63 @@ void testUnderflowAndOverflow() {
Expect.equals(dtBase1.minute, dtTick.minute);
Expect.equals(dtBase1.second, dtTick.second);
Expect.equals(dtBase1.millisecond, dtTick.millisecond);
+ Expect.equals(dtBase1.microsecond, dtTick.microsecond);
+
+ if (!supportsMicroseconds) return;
+
+ // Microsecond
+ print(" >>> Microsecond+");
+ dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
+ dtBase.minute, dtBase.second, dtBase.millisecond, 1000);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond + 1, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
+
+ print(" >>> Microsecond-");
+ dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
+ dtBase.minute, dtBase.second, dtBase.millisecond, -1000);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond - 1, dt.millisecond);
+ Expect.equals(0, dt.microsecond);
+
+ // Flowing all the way up the chain.
+ print(" >>> Flow+ 2");
+ dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999, 999);
+ dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day,
+ dtBase1.hour, dtBase1.minute, dtBase1.second,
+ dtBase1.millisecond, dtBase1.microsecond + 1);
+ Expect.equals(dtBase1.year + 1, dtTick.year);
+ Expect.equals(1, dtTick.month);
+ Expect.equals(1, dtTick.day);
+ Expect.equals(0, dtTick.hour);
+ Expect.equals(0, dtTick.minute);
+ Expect.equals(0, dtTick.second);
+ Expect.equals(0, dtTick.millisecond);
+ Expect.equals(0, dtTick.microsecond);
+
+ print(" >>> Flow- 2");
+ dtBase1 = new DateTime(2012, 1, 1, 0, 0, 0, 0, 0);
+ dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, dtBase1.hour,
+ dtBase1.minute, dtBase1.second, dtBase1.millisecond,
+ dtBase1.microsecond - 1);
+ Expect.equals(dtBase1.year - 1, dtTick.year);
+ Expect.equals(12, dtTick.month);
+ Expect.equals(31, dtTick.day);
+ Expect.equals(23, dtTick.hour);
+ Expect.equals(59, dtTick.minute);
+ Expect.equals(59, dtTick.second);
+ Expect.equals(999, dtTick.millisecond);
+ Expect.equals(999, dtTick.microsecond);
}
void testDateStrings() {
@@ -640,6 +915,7 @@ void testDateStrings() {
Expect.equals(0, dt4.minute);
Expect.equals(0, dt4.second);
Expect.equals(0, dt4.millisecond);
+ Expect.equals(0, dt4.microsecond);
Expect.isTrue(dt4.isUtc);
var dt5 = DateTime.parse("0099-01-02");
Expect.equals(99, dt5.year);
@@ -649,17 +925,23 @@ void testDateStrings() {
Expect.equals(0, dt5.minute);
Expect.equals(0, dt5.second);
Expect.equals(0, dt5.millisecond);
+ Expect.equals(0, dt5.microsecond);
Expect.isFalse(dt5.isUtc);
var dt6 = DateTime.parse("2012-01-01 00:00:10.012");
Expect.equals(12, dt6.millisecond);
+ Expect.equals(0, dt6.microsecond);
dt6 = DateTime.parse("2012-01-01 00:00:10.003");
Expect.equals(3, dt6.millisecond);
+ Expect.equals(0, dt6.microsecond);
dt6 = DateTime.parse("2012-01-01 00:00:10.5");
Expect.equals(500, dt6.millisecond);
+ Expect.equals(0, dt6.microsecond);
dt6 = DateTime.parse("2012-01-01 00:00:10.003Z");
Expect.equals(3, dt6.millisecond);
+ Expect.equals(0, dt6.microsecond);
dt6 = DateTime.parse("2012-01-01 00:00:10.5z");
Expect.equals(500, dt6.millisecond);
+ Expect.equals(0, dt6.microsecond);
var dt7 = DateTime.parse("2011-05-11T18:58:35Z");
Expect.equals(1305140315000, dt7.millisecondsSinceEpoch);
var dt8 = DateTime.parse("-1234-01-01T00:00:00Z");
@@ -670,6 +952,7 @@ void testDateStrings() {
Expect.equals(0, dt8.minute);
Expect.equals(0, dt8.second);
Expect.equals(0, dt8.millisecond);
+ Expect.equals(0, dt8.microsecond);
Expect.isTrue(dt8.isUtc);
var dt9 = DateTime.parse("-1234-01-01T00:00:00");
Expect.equals(-1234, dt9.year);
@@ -679,6 +962,7 @@ void testDateStrings() {
Expect.equals(0, dt9.minute);
Expect.equals(0, dt9.second);
Expect.equals(0, dt9.millisecond);
+ Expect.equals(0, dt9.microsecond);
Expect.isFalse(dt9.isUtc);
var dt10 = DateTime.parse("-12340101");
Expect.equals(-1234, dt10.year);
@@ -688,6 +972,7 @@ void testDateStrings() {
Expect.equals(0, dt10.minute);
Expect.equals(0, dt10.second);
Expect.equals(0, dt10.millisecond);
+ Expect.equals(0, dt10.microsecond);
Expect.isFalse(dt10.isUtc);
dt1 = DateTime.parse("2012-02-27 13:27:00");
Expect.equals(2012, dt1.year);
@@ -697,6 +982,7 @@ void testDateStrings() {
Expect.equals(27, dt1.minute);
Expect.equals(0, dt1.second);
Expect.equals(0, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
Expect.equals(false, dt1.isUtc);
dt1 = DateTime.parse("2012-02-27 13:27:00.423z");
Expect.equals(2012, dt1.year);
@@ -706,6 +992,7 @@ void testDateStrings() {
Expect.equals(27, dt1.minute);
Expect.equals(0, dt1.second);
Expect.equals(423, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
Expect.equals(true, dt1.isUtc);
dt1 = DateTime.parse("20120227 13:27:00");
Expect.equals(2012, dt1.year);
@@ -715,6 +1002,7 @@ void testDateStrings() {
Expect.equals(27, dt1.minute);
Expect.equals(0, dt1.second);
Expect.equals(0, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
Expect.equals(false, dt1.isUtc);
dt1 = DateTime.parse("20120227T132700");
Expect.equals(2012, dt1.year);
@@ -724,6 +1012,7 @@ void testDateStrings() {
Expect.equals(27, dt1.minute);
Expect.equals(0, dt1.second);
Expect.equals(0, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
Expect.equals(false, dt1.isUtc);
dt1 = DateTime.parse("20120227");
Expect.equals(2012, dt1.year);
@@ -733,6 +1022,7 @@ void testDateStrings() {
Expect.equals(0, dt1.minute);
Expect.equals(0, dt1.second);
Expect.equals(0, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
Expect.equals(false, dt1.isUtc);
dt1 = DateTime.parse("2012-02-27T14Z");
Expect.equals(2012, dt1.year);
@@ -742,6 +1032,7 @@ void testDateStrings() {
Expect.equals(0, dt1.minute);
Expect.equals(0, dt1.second);
Expect.equals(0, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
Expect.equals(true, dt1.isUtc);
dt1 = DateTime.parse("-123450101 00:00:00 Z");
Expect.equals(-12345, dt1.year);
@@ -751,28 +1042,51 @@ void testDateStrings() {
Expect.equals(0, dt1.minute);
Expect.equals(0, dt1.second);
Expect.equals(0, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
Expect.equals(true, dt1.isUtc);
- // We only support millisecond. If the user supplies more data (the "51"
- // here), we round.
- // If (eventually) we support more than just millisecond this test could
- // fail. Please update the test in this case.
dt1 = DateTime.parse("1999-01-02 23:59:59.99951");
- Expect.equals(1999, dt1.year);
- Expect.equals(1, dt1.month);
- Expect.equals(3, dt1.day);
- Expect.equals(0, dt1.hour);
- Expect.equals(0, dt1.minute);
- Expect.equals(0, dt1.second);
- Expect.equals(0, dt1.millisecond);
+ if (supportsMicroseconds) {
+ Expect.equals(1999, dt1.year);
+ Expect.equals(1, dt1.month);
+ Expect.equals(2, dt1.day);
+ Expect.equals(23, dt1.hour);
+ Expect.equals(59, dt1.minute);
+ Expect.equals(59, dt1.second);
+ Expect.equals(999, dt1.millisecond);
+ Expect.equals(510, dt1.microsecond);
+ } else {
+ // We only support millisecond. If the user supplies more data (the "51"
+ // here), we round.
+ Expect.equals(1999, dt1.year);
+ Expect.equals(1, dt1.month);
+ Expect.equals(3, dt1.day);
+ Expect.equals(0, dt1.hour);
+ Expect.equals(0, dt1.minute);
+ Expect.equals(0, dt1.second);
+ Expect.equals(0, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
+ }
Expect.equals(false, dt1.isUtc);
dt1 = DateTime.parse("1999-01-02 23:58:59.99951Z");
- Expect.equals(1999, dt1.year);
- Expect.equals(1, dt1.month);
- Expect.equals(2, dt1.day);
- Expect.equals(23, dt1.hour);
- Expect.equals(59, dt1.minute);
- Expect.equals(0, dt1.second);
- Expect.equals(0, dt1.millisecond);
+ if (supportsMicroseconds) {
+ Expect.equals(1999, dt1.year);
+ Expect.equals(1, dt1.month);
+ Expect.equals(2, dt1.day);
+ Expect.equals(23, dt1.hour);
+ Expect.equals(58, dt1.minute);
+ Expect.equals(59, dt1.second);
+ Expect.equals(999, dt1.millisecond);
+ Expect.equals(510, dt1.microsecond);
+ } else {
+ Expect.equals(1999, dt1.year);
+ Expect.equals(1, dt1.month);
+ Expect.equals(2, dt1.day);
+ Expect.equals(23, dt1.hour);
+ Expect.equals(59, dt1.minute);
+ Expect.equals(0, dt1.second);
+ Expect.equals(0, dt1.millisecond);
+ Expect.equals(0, dt1.microsecond);
+ }
Expect.equals(true, dt1.isUtc);
dt1 = DateTime.parse("0009-09-09 09:09:09.009Z");
Expect.equals(9, dt1.year);
@@ -866,11 +1180,22 @@ void testDateStrings() {
(e) => e is FormatException);
Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.001Z"),
(e) => e is FormatException);
+ if (supportsMicroseconds) {
+ Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.000001Z"),
+ (e) => e is FormatException);
+ } else {
+ dt1 = DateTime.parse("275760-09-13T00:00:00.000001Z");
+ }
// first valid time; should not throw.
dt1 = DateTime.parse("-271821-04-20T00:00:00.000Z");
Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999Z"),
(e) => e is FormatException);
+
+ if (supportsMicroseconds) {
+ Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999999Z"),
+ (e) => e is FormatException);
+ }
}
void testWeekday() {
@@ -932,6 +1257,14 @@ void testToStrings() {
test("1970-01-01", "00:00:00.000");
test("1969-12-31", "23:59:59.999");
test("1969-09-09", "00:09:09.009");
+
+ if (supportsMicroseconds) {
+ test("2000-01-01", "12:00:00.000001");
+ test("-2000-01-01", "12:00:00.000001");
+ test("1970-01-01", "00:00:00.000001");
+ test("1969-12-31", "23:59:59.999999");
+ test("1969-09-09", "00:09:09.009999");
+ }
}
void testIsoString() {
@@ -952,11 +1285,50 @@ void testIsoString() {
Expect.equals("+010000-01-01T23:59:59.999Z", d.toIso8601String());
d = new DateTime.utc(-10000, 1, 1, 23, 59, 59, 999);
Expect.equals("-010000-01-01T23:59:59.999Z", d.toIso8601String());
+
+ if (!supportsMicroseconds) return;
+
+ d = new DateTime(9999, 1, 1, 23, 59, 59, 999, 999);
+ Expect.equals("9999-01-01T23:59:59.999999", d.toIso8601String());
+ d = new DateTime(-9999, 1, 1, 23, 59, 59, 999, 999);
+ Expect.equals("-9999-01-01T23:59:59.999999", d.toIso8601String());
+ d = new DateTime.utc(9999, 1, 1, 23, 59, 59, 999, 999);
+ Expect.equals("9999-01-01T23:59:59.999999Z", d.toIso8601String());
+ d = new DateTime.utc(-9999, 1, 1, 23, 59, 59, 999, 999);
+ Expect.equals("-9999-01-01T23:59:59.999999Z", d.toIso8601String());
+
+ d = new DateTime(10000, 1, 1, 23, 59, 59, 999, 999);
+ Expect.equals("+010000-01-01T23:59:59.999999", d.toIso8601String());
+ d = new DateTime(-10000, 1, 1, 23, 59, 59, 999, 999);
+ Expect.equals("-010000-01-01T23:59:59.999999", d.toIso8601String());
+ d = new DateTime.utc(10000, 1, 1, 23, 59, 59, 999, 999);
+ Expect.equals("+010000-01-01T23:59:59.999999Z", d.toIso8601String());
+ d = new DateTime.utc(-10000, 1, 1, 23, 59, 59, 999, 999);
+ Expect.equals("-010000-01-01T23:59:59.999999Z", d.toIso8601String());
+
+ d = new DateTime(9999, 1, 1, 23, 49, 59, 989, 979);
+ Expect.equals("9999-01-01T23:49:59.989979", d.toIso8601String());
+ d = new DateTime(-9999, 1, 1, 23, 49, 59, 989, 979);
+ Expect.equals("-9999-01-01T23:49:59.989979", d.toIso8601String());
+ d = new DateTime.utc(9999, 1, 1, 23, 49, 59, 989, 979);
+ Expect.equals("9999-01-01T23:49:59.989979Z", d.toIso8601String());
+ d = new DateTime.utc(-9999, 1, 1, 23, 49, 59, 989, 979);
+ Expect.equals("-9999-01-01T23:49:59.989979Z", d.toIso8601String());
+
+ d = new DateTime(10000, 1, 1, 23, 49, 59, 989, 979);
+ Expect.equals("+010000-01-01T23:49:59.989979", d.toIso8601String());
+ d = new DateTime(-10000, 1, 1, 23, 49, 59, 989, 979);
+ Expect.equals("-010000-01-01T23:49:59.989979", d.toIso8601String());
+ d = new DateTime.utc(10000, 1, 1, 23, 49, 59, 989, 979);
+ Expect.equals("+010000-01-01T23:49:59.989979Z", d.toIso8601String());
+ d = new DateTime.utc(-10000, 1, 1, 23, 49, 59, 989, 979);
+ Expect.equals("-010000-01-01T23:49:59.989979Z", d.toIso8601String());
}
void main() {
testNow();
- testValue();
+ testMillisecondsSinceEpoch();
+ testMicrosecondsSinceEpoch();
testConstructors();
testUTCGetters();
testLocalGetters();
« no previous file with comments | « tests/corelib/date_time_parse_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698