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

Unified Diff: tests/corelib/src/DateTimeTest.dart

Issue 9568011: Unify Date.fromString and support more Iso 8601. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 8 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 | « tests/co19/co19-runtime.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/src/DateTimeTest.dart
diff --git a/tests/corelib/src/DateTimeTest.dart b/tests/corelib/src/DateTimeTest.dart
index 42b358e3517948443fb5ec8ce3ac5a81a345a796..67f1de1b501b89a3e974a81d52123fc7e0c051c6 100644
--- a/tests/corelib/src/DateTimeTest.dart
+++ b/tests/corelib/src/DateTimeTest.dart
@@ -277,6 +277,16 @@ class DateTest {
dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
dt1.seconds, dt1.milliseconds, const TimeZone.utc());
Expect.equals(dt1.value, dt3.value);
+ dt3 = new Date.withTimeZone(99, 1, 2, 10, 11, 12, 0,
+ const TimeZone.utc());
+ Expect.equals(99, dt3.year);
+ Expect.equals(1, dt3.month);
+ Expect.equals(2, dt3.day);
+ Expect.equals(10, dt3.hours);
+ Expect.equals(11, dt3.minutes);
+ Expect.equals(12, dt3.seconds);
+ Expect.equals(0, dt3.milliseconds);
+ Expect.equals(true, dt3.isUtc());
}
static void testChangeTimeZone() {
@@ -324,12 +334,160 @@ class DateTest {
var dt1 = new Date.fromString("2011-05-11 18:58:35Z");
Expect.equals(1305140315000, dt1.value);
Expect.isTrue(dt1.isUtc());
+ dt1 = new Date.fromString("20110511 18:58:35z");
+ Expect.equals(1305140315000, dt1.value);
+ Expect.isTrue(dt1.isUtc());
+ dt1 = new Date.fromString("+20110511 18:58:35z");
+ Expect.equals(1305140315000, dt1.value);
+ Expect.isTrue(dt1.isUtc());
var str = dt1.toString();
var dt2 = new Date.fromString(str);
Expect.equals(true, dt1 == dt2);
var dt3 = dt1.changeTimeZone(const TimeZone.utc());
str = dt3.toString();
Expect.equals("2011-05-11 18:58:35.000Z", str);
+ var dt4 = new Date.fromString("-1234-01-01 00:00:00Z");
+ Expect.equals(-1234, dt4.year);
+ Expect.equals(1, dt4.month);
+ Expect.equals(1, dt4.day);
+ Expect.equals(0, dt4.hours);
+ Expect.equals(0, dt4.minutes);
+ Expect.equals(0, dt4.seconds);
+ Expect.equals(0, dt4.milliseconds);
+ Expect.isTrue(dt4.isUtc());
+ var dt5 = new Date.fromString("0099-01-02");
+ Expect.equals(99, dt5.year);
+ Expect.equals(1, dt5.month);
+ Expect.equals(2, dt5.day);
+ Expect.equals(0, dt5.hours);
+ Expect.equals(0, dt5.minutes);
+ Expect.equals(0, dt5.seconds);
+ Expect.equals(0, dt5.milliseconds);
+ Expect.isFalse(dt5.isUtc());
+ var dt6 = new Date.fromString("2012-01-01 00:00:10.012");
+ Expect.equals(12, dt6.milliseconds);
+ dt6 = new Date.fromString("2012-01-01 00:00:10.003");
+ Expect.equals(3, dt6.milliseconds);
+ dt6 = new Date.fromString("2012-01-01 00:00:10.5");
+ Expect.equals(500, dt6.milliseconds);
+ dt6 = new Date.fromString("2012-01-01 00:00:10.003Z");
+ Expect.equals(3, dt6.milliseconds);
+ dt6 = new Date.fromString("2012-01-01 00:00:10.5z");
+ Expect.equals(500, dt6.milliseconds);
+ var dt7 = new Date.fromString("2011-05-11T18:58:35Z");
+ Expect.equals(1305140315000, dt7.value);
+ var dt8 = new Date.fromString("-1234-01-01T00:00:00Z");
+ Expect.equals(-1234, dt8.year);
+ Expect.equals(1, dt8.month);
+ Expect.equals(1, dt8.day);
+ Expect.equals(0, dt8.hours);
+ Expect.equals(0, dt8.minutes);
+ Expect.equals(0, dt8.seconds);
+ Expect.equals(0, dt8.milliseconds);
+ Expect.isTrue(dt8.isUtc());
+ var dt9 = new Date.fromString("-1234-01-01T00:00:00");
+ Expect.equals(-1234, dt9.year);
+ Expect.equals(1, dt9.month);
+ Expect.equals(1, dt9.day);
+ Expect.equals(0, dt9.hours);
+ Expect.equals(0, dt9.minutes);
+ Expect.equals(0, dt9.seconds);
+ Expect.equals(0, dt9.milliseconds);
+ Expect.isFalse(dt9.isUtc());
+ var dt10 = new Date.fromString("-12340101");
+ Expect.equals(-1234, dt10.year);
+ Expect.equals(1, dt10.month);
+ Expect.equals(1, dt10.day);
+ Expect.equals(0, dt10.hours);
+ Expect.equals(0, dt10.minutes);
+ Expect.equals(0, dt10.seconds);
+ Expect.equals(0, dt10.milliseconds);
+ Expect.isFalse(dt10.isUtc());
+ dt1 = new Date.fromString("2012-02-27 13:27:00");
+ Expect.equals(2012, dt1.year);
+ Expect.equals(2, dt1.month);
+ Expect.equals(27, dt1.day);
+ Expect.equals(13, dt1.hours);
+ Expect.equals(27, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(0, dt1.milliseconds);
+ Expect.equals(false, dt1.isUtc());
+ dt1 = new Date.fromString("2012-02-27 13:27:00.423z");
+ Expect.equals(2012, dt1.year);
+ Expect.equals(2, dt1.month);
+ Expect.equals(27, dt1.day);
+ Expect.equals(13, dt1.hours);
+ Expect.equals(27, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(423, dt1.milliseconds);
+ Expect.equals(true, dt1.isUtc());
+ dt1 = new Date.fromString("20120227 13:27:00");
+ Expect.equals(2012, dt1.year);
+ Expect.equals(2, dt1.month);
+ Expect.equals(27, dt1.day);
+ Expect.equals(13, dt1.hours);
+ Expect.equals(27, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(0, dt1.milliseconds);
+ Expect.equals(false, dt1.isUtc());
+ dt1 = new Date.fromString("20120227T132700");
+ Expect.equals(2012, dt1.year);
+ Expect.equals(2, dt1.month);
+ Expect.equals(27, dt1.day);
+ Expect.equals(13, dt1.hours);
+ Expect.equals(27, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(0, dt1.milliseconds);
+ Expect.equals(false, dt1.isUtc());
+ dt1 = new Date.fromString("20120227");
+ Expect.equals(2012, dt1.year);
+ Expect.equals(2, dt1.month);
+ Expect.equals(27, dt1.day);
+ Expect.equals(0, dt1.hours);
+ Expect.equals(0, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(0, dt1.milliseconds);
+ Expect.equals(false, dt1.isUtc());
+ dt1 = new Date.fromString("2012-02-27T14Z");
+ Expect.equals(2012, dt1.year);
+ Expect.equals(2, dt1.month);
+ Expect.equals(27, dt1.day);
+ Expect.equals(14, dt1.hours);
+ Expect.equals(0, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(0, dt1.milliseconds);
+ Expect.equals(true, dt1.isUtc());
+ dt1 = new Date.fromString("-123450101 00:00:00 Z");
+ Expect.equals(-12345, dt1.year);
+ Expect.equals(1, dt1.month);
+ Expect.equals(1, dt1.day);
+ Expect.equals(0, dt1.hours);
+ Expect.equals(0, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(0, dt1.milliseconds);
+ Expect.equals(true, dt1.isUtc());
+ // We only support milliseconds. If the user supplies more data (the "51"
+ // here), we round.
+ // If (eventually) we support more than just milliseconds this test could
+ // fail. Please update the test in this case.
+ dt1 = new Date.fromString("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.hours);
+ Expect.equals(0, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(0, dt1.milliseconds);
+ Expect.equals(false, dt1.isUtc());
+ dt1 = new Date.fromString("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.hours);
+ Expect.equals(59, dt1.minutes);
+ Expect.equals(0, dt1.seconds);
+ Expect.equals(0, dt1.milliseconds);
+ Expect.equals(true, dt1.isUtc());
}
static void testWeekday() {
« no previous file with comments | « tests/co19/co19-runtime.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698