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

Side by Side Diff: tests/corelib/date_time_test.dart

Issue 10411057: Deprecate use of timezones. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix code using old api. Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Dart test program for Date. 5 // Dart test program for Date.
6 6
7 class DateTest { 7 class DateTest {
8 // Tests if the time moves eventually forward. 8 // Tests if the time moves eventually forward.
9 static void testNow() { 9 static void testNow() {
10 var t1 = new Date.now(); 10 var t1 = new Date.now();
11 bool timeMovedForward = false; 11 bool timeMovedForward = false;
12 for (int i = 0; i < 1000000; i++) { 12 for (int i = 0; i < 1000000; i++) {
13 var t2 = new Date.now(); 13 var t2 = new Date.now();
14 if (t1.value < t2.value) { 14 if (t1.value < t2.value) {
15 timeMovedForward = true; 15 timeMovedForward = true;
16 break; 16 break;
17 } 17 }
18 } 18 }
19 Expect.equals(true, timeMovedForward); 19 Expect.equals(true, timeMovedForward);
20 } 20 }
21 21
22 static void testValue() { 22 static void testValue() {
23 var dt1 = new Date.now(); 23 var dt1 = new Date.now();
24 var value = dt1.value; 24 var value = dt1.value;
25 var dt2 = new Date.fromEpoch(value, new TimeZone.local()); 25 var dt2 = new Date.fromEpoch(value);
26 Expect.equals(value, dt2.value); 26 Expect.equals(value, dt2.value);
27 } 27 }
28 28
29 static void testFarAwayDates() { 29 static void testFarAwayDates() {
30 Date dt = new Date.fromEpoch(1000000000000001, const TimeZone.utc()); 30 Date dt = new Date.fromEpoch(1000000000000001, isUtc: true);
31 Expect.equals(33658, dt.year); 31 Expect.equals(33658, dt.year);
32 Expect.equals(9, dt.month); 32 Expect.equals(9, dt.month);
33 Expect.equals(27, dt.day); 33 Expect.equals(27, dt.day);
34 Expect.equals(1, dt.hours); 34 Expect.equals(1, dt.hours);
35 Expect.equals(46, dt.minutes); 35 Expect.equals(46, dt.minutes);
36 Expect.equals(40, dt.seconds); 36 Expect.equals(40, dt.seconds);
37 Expect.equals(1, dt.milliseconds); 37 Expect.equals(1, dt.milliseconds);
38 dt = new Date.fromEpoch(-1000000000000001, const TimeZone.utc()); 38 dt = new Date.fromEpoch(-1000000000000001, isUtc: true);
39 Expect.equals(-29719, dt.year); 39 Expect.equals(-29719, dt.year);
40 Expect.equals(4, dt.month); 40 Expect.equals(4, dt.month);
41 Expect.equals(5, dt.day); 41 Expect.equals(5, dt.day);
42 Expect.equals(22, dt.hours); 42 Expect.equals(22, dt.hours);
43 Expect.equals(13, dt.minutes); 43 Expect.equals(13, dt.minutes);
44 Expect.equals(19, dt.seconds); 44 Expect.equals(19, dt.seconds);
45 Expect.equals(999, dt.milliseconds); 45 Expect.equals(999, dt.milliseconds);
46 // Same with local zone. 46 // Same with local zone.
47 dt = new Date.fromEpoch(1000000000000001, new TimeZone.local()); 47 dt = new Date.fromEpoch(1000000000000001);
48 Expect.equals(33658, dt.year); 48 Expect.equals(33658, dt.year);
49 Expect.equals(9, dt.month); 49 Expect.equals(9, dt.month);
50 Expect.equals(true, dt.day == 27 || dt.day == 26); 50 Expect.equals(true, dt.day == 27 || dt.day == 26);
51 // Not much we can test for local hours. 51 // Not much we can test for local hours.
52 Expect.equals(true, dt.hours >= 0 && dt.hours < 24); 52 Expect.equals(true, dt.hours >= 0 && dt.hours < 24);
53 // Timezones can have offsets down to 15 minutes. 53 // Timezones can have offsets down to 15 minutes.
54 Expect.equals(true, dt.minutes % 15 == 46 % 15); 54 Expect.equals(true, dt.minutes % 15 == 46 % 15);
55 Expect.equals(40, dt.seconds); 55 Expect.equals(40, dt.seconds);
56 Expect.equals(1, dt.milliseconds); 56 Expect.equals(1, dt.milliseconds);
57 dt = new Date.fromEpoch(-1000000000000001, new TimeZone.local()); 57 dt = new Date.fromEpoch(-1000000000000001);
58 Expect.equals(-29719, dt.year); 58 Expect.equals(-29719, dt.year);
59 Expect.equals(4, dt.month); 59 Expect.equals(4, dt.month);
60 Expect.equals(true, 5 == dt.day || 6 == dt.day); 60 Expect.equals(true, 5 == dt.day || 6 == dt.day);
61 // Not much we can test for local hours. 61 // Not much we can test for local hours.
62 Expect.equals(true, dt.hours >= 0 && dt.hours < 24); 62 Expect.equals(true, dt.hours >= 0 && dt.hours < 24);
63 // Timezones can have offsets down to 15 minutes. 63 // Timezones can have offsets down to 15 minutes.
64 Expect.equals(true, dt.minutes % 15 == 13); 64 Expect.equals(true, dt.minutes % 15 == 13);
65 Expect.equals(19, dt.seconds); 65 Expect.equals(19, dt.seconds);
66 Expect.equals(999, dt.milliseconds); 66 Expect.equals(999, dt.milliseconds);
67 } 67 }
68 68
69 static void testEquivalentYears() { 69 static void testEquivalentYears() {
70 // All hardcoded values come from V8. This means that the values are not 70 // All hardcoded values come from V8. This means that the values are not
71 // necessarily correct (see limitations of Date object in 71 // necessarily correct (see limitations of Date object in
72 // EcmaScript 15.9.1 and in particular 15.9.1.8/9). 72 // EcmaScript 15.9.1 and in particular 15.9.1.8/9).
73 Date dt = new Date.fromEpoch(-31485600000, const TimeZone.utc()); 73 Date dt = new Date.fromEpoch(-31485600000, isUtc: true);
74 Expect.equals(1969, dt.year); 74 Expect.equals(1969, dt.year);
75 Expect.equals(1, dt.month); 75 Expect.equals(1, dt.month);
76 Expect.equals(1, dt.day); 76 Expect.equals(1, dt.day);
77 Expect.equals(14, dt.hours); 77 Expect.equals(14, dt.hours);
78 Expect.equals(0, dt.minutes); 78 Expect.equals(0, dt.minutes);
79 Expect.equals(0, dt.seconds); 79 Expect.equals(0, dt.seconds);
80 Expect.equals(0, dt.milliseconds); 80 Expect.equals(0, dt.milliseconds);
81 dt = new Date.fromEpoch(-63108000000, const TimeZone.utc()); 81 dt = new Date.fromEpoch(-63108000000, isUtc: true);
82 Expect.equals(1968, dt.year); 82 Expect.equals(1968, dt.year);
83 Expect.equals(1, dt.month); 83 Expect.equals(1, dt.month);
84 Expect.equals(1, dt.day); 84 Expect.equals(1, dt.day);
85 Expect.equals(14, dt.hours); 85 Expect.equals(14, dt.hours);
86 Expect.equals(0, dt.minutes); 86 Expect.equals(0, dt.minutes);
87 Expect.equals(0, dt.seconds); 87 Expect.equals(0, dt.seconds);
88 Expect.equals(0, dt.milliseconds); 88 Expect.equals(0, dt.milliseconds);
89 dt = new Date.fromEpoch(-94644000000, const TimeZone.utc()); 89 dt = new Date.fromEpoch(-94644000000, isUtc: true);
90 Expect.equals(1967, dt.year); 90 Expect.equals(1967, dt.year);
91 Expect.equals(1, dt.month); 91 Expect.equals(1, dt.month);
92 Expect.equals(1, dt.day); 92 Expect.equals(1, dt.day);
93 Expect.equals(14, dt.hours); 93 Expect.equals(14, dt.hours);
94 Expect.equals(0, dt.minutes); 94 Expect.equals(0, dt.minutes);
95 Expect.equals(0, dt.seconds); 95 Expect.equals(0, dt.seconds);
96 Expect.equals(0, dt.milliseconds); 96 Expect.equals(0, dt.milliseconds);
97 dt = new Date.fromEpoch(-126180000000, const TimeZone.utc()); 97 dt = new Date.fromEpoch(-126180000000, isUtc: true);
98 Expect.equals(1966, dt.year); 98 Expect.equals(1966, dt.year);
99 Expect.equals(1, dt.month); 99 Expect.equals(1, dt.month);
100 Expect.equals(1, dt.day); 100 Expect.equals(1, dt.day);
101 Expect.equals(14, dt.hours); 101 Expect.equals(14, dt.hours);
102 Expect.equals(0, dt.minutes); 102 Expect.equals(0, dt.minutes);
103 Expect.equals(0, dt.seconds); 103 Expect.equals(0, dt.seconds);
104 Expect.equals(0, dt.milliseconds); 104 Expect.equals(0, dt.milliseconds);
105 dt = new Date.fromEpoch(-157716000000, const TimeZone.utc()); 105 dt = new Date.fromEpoch(-157716000000, isUtc: true);
106 Expect.equals(1965, dt.year); 106 Expect.equals(1965, dt.year);
107 Expect.equals(1, dt.month); 107 Expect.equals(1, dt.month);
108 Expect.equals(1, dt.day); 108 Expect.equals(1, dt.day);
109 Expect.equals(14, dt.hours); 109 Expect.equals(14, dt.hours);
110 Expect.equals(0, dt.minutes); 110 Expect.equals(0, dt.minutes);
111 Expect.equals(0, dt.seconds); 111 Expect.equals(0, dt.seconds);
112 Expect.equals(0, dt.milliseconds); 112 Expect.equals(0, dt.milliseconds);
113 dt = new Date.fromEpoch(-2177402400000, const TimeZone.utc()); 113 dt = new Date.fromEpoch(-2177402400000, isUtc: true);
114 Expect.equals(1901, dt.year); 114 Expect.equals(1901, dt.year);
115 Expect.equals(1, dt.month); 115 Expect.equals(1, dt.month);
116 Expect.equals(1, dt.day); 116 Expect.equals(1, dt.day);
117 Expect.equals(14, dt.hours); 117 Expect.equals(14, dt.hours);
118 Expect.equals(0, dt.minutes); 118 Expect.equals(0, dt.minutes);
119 Expect.equals(0, dt.seconds); 119 Expect.equals(0, dt.seconds);
120 Expect.equals(0, dt.milliseconds); 120 Expect.equals(0, dt.milliseconds);
121 dt = new Date.fromEpoch(-5333076000000, const TimeZone.utc()); 121 dt = new Date.fromEpoch(-5333076000000, isUtc: true);
122 Expect.equals(1801, dt.year); 122 Expect.equals(1801, dt.year);
123 Expect.equals(1, dt.month); 123 Expect.equals(1, dt.month);
124 Expect.equals(1, dt.day); 124 Expect.equals(1, dt.day);
125 Expect.equals(14, dt.hours); 125 Expect.equals(14, dt.hours);
126 Expect.equals(0, dt.minutes); 126 Expect.equals(0, dt.minutes);
127 Expect.equals(0, dt.seconds); 127 Expect.equals(0, dt.seconds);
128 Expect.equals(0, dt.milliseconds); 128 Expect.equals(0, dt.milliseconds);
129 dt = new Date.fromEpoch(-8520285600000, const TimeZone.utc()); 129 dt = new Date.fromEpoch(-8520285600000, isUtc: true);
130 Expect.equals(1700, dt.year); 130 Expect.equals(1700, dt.year);
131 Expect.equals(1, dt.month); 131 Expect.equals(1, dt.month);
132 Expect.equals(1, dt.day); 132 Expect.equals(1, dt.day);
133 Expect.equals(14, dt.hours); 133 Expect.equals(14, dt.hours);
134 Expect.equals(0, dt.minutes); 134 Expect.equals(0, dt.minutes);
135 Expect.equals(0, dt.seconds); 135 Expect.equals(0, dt.seconds);
136 Expect.equals(0, dt.milliseconds); 136 Expect.equals(0, dt.milliseconds);
137 dt = new Date.fromEpoch(-14831719200000, const TimeZone.utc()); 137 dt = new Date.fromEpoch(-14831719200000, isUtc: true);
138 Expect.equals(1500, dt.year); 138 Expect.equals(1500, dt.year);
139 Expect.equals(1, dt.month); 139 Expect.equals(1, dt.month);
140 Expect.equals(1, dt.day); 140 Expect.equals(1, dt.day);
141 Expect.equals(14, dt.hours); 141 Expect.equals(14, dt.hours);
142 Expect.equals(0, dt.minutes); 142 Expect.equals(0, dt.minutes);
143 Expect.equals(0, dt.seconds); 143 Expect.equals(0, dt.seconds);
144 Expect.equals(0, dt.milliseconds); 144 Expect.equals(0, dt.milliseconds);
145 dt = new Date.fromEpoch(-59011408800000, const TimeZone.utc()); 145 dt = new Date.fromEpoch(-59011408800000, isUtc: true);
146 Expect.equals(100, dt.year); 146 Expect.equals(100, dt.year);
147 Expect.equals(1, dt.month); 147 Expect.equals(1, dt.month);
148 Expect.equals(1, dt.day); 148 Expect.equals(1, dt.day);
149 Expect.equals(14, dt.hours); 149 Expect.equals(14, dt.hours);
150 Expect.equals(0, dt.minutes); 150 Expect.equals(0, dt.minutes);
151 Expect.equals(0, dt.seconds); 151 Expect.equals(0, dt.seconds);
152 Expect.equals(0, dt.milliseconds); 152 Expect.equals(0, dt.milliseconds);
153 dt = new Date.fromEpoch(-62011408800000, const TimeZone.utc()); 153 dt = new Date.fromEpoch(-62011408800000, isUtc: true);
154 Expect.equals(4, dt.year); 154 Expect.equals(4, dt.year);
155 Expect.equals(12, dt.month); 155 Expect.equals(12, dt.month);
156 Expect.equals(8, dt.day); 156 Expect.equals(8, dt.day);
157 Expect.equals(8, dt.hours); 157 Expect.equals(8, dt.hours);
158 Expect.equals(40, dt.minutes); 158 Expect.equals(40, dt.minutes);
159 Expect.equals(0, dt.seconds); 159 Expect.equals(0, dt.seconds);
160 Expect.equals(0, dt.milliseconds); 160 Expect.equals(0, dt.milliseconds);
161 dt = new Date.fromEpoch(-64011408800000, const TimeZone.utc()); 161 dt = new Date.fromEpoch(-64011408800000, isUtc: true);
162 Expect.equals(-59, dt.year); 162 Expect.equals(-59, dt.year);
163 Expect.equals(7, dt.month); 163 Expect.equals(7, dt.month);
164 Expect.equals(24, dt.day); 164 Expect.equals(24, dt.day);
165 Expect.equals(5, dt.hours); 165 Expect.equals(5, dt.hours);
166 Expect.equals(6, dt.minutes); 166 Expect.equals(6, dt.minutes);
167 Expect.equals(40, dt.seconds); 167 Expect.equals(40, dt.seconds);
168 Expect.equals(0, dt.milliseconds); 168 Expect.equals(0, dt.milliseconds);
169 final int SECONDS_YEAR_2035 = 2051222400; 169 final int SECONDS_YEAR_2035 = 2051222400;
170 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 + 1, const TimeZone.utc()); 170 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 + 1, isUtc: true);
171 Expect.equals(2035, dt.year); 171 Expect.equals(2035, dt.year);
172 Expect.equals(1, dt.month); 172 Expect.equals(1, dt.month);
173 Expect.equals(1, dt.day); 173 Expect.equals(1, dt.day);
174 Expect.equals(0, dt.hours); 174 Expect.equals(0, dt.hours);
175 Expect.equals(0, dt.minutes); 175 Expect.equals(0, dt.minutes);
176 Expect.equals(0, dt.seconds); 176 Expect.equals(0, dt.seconds);
177 Expect.equals(1, dt.milliseconds); 177 Expect.equals(1, dt.milliseconds);
178 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 - 1, const TimeZone.utc()); 178 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 - 1, isUtc: true);
179 Expect.equals(2034, dt.year); 179 Expect.equals(2034, dt.year);
180 Expect.equals(12, dt.month); 180 Expect.equals(12, dt.month);
181 Expect.equals(31, dt.day); 181 Expect.equals(31, dt.day);
182 Expect.equals(23, dt.hours); 182 Expect.equals(23, dt.hours);
183 Expect.equals(59, dt.minutes); 183 Expect.equals(59, dt.minutes);
184 Expect.equals(59, dt.seconds); 184 Expect.equals(59, dt.seconds);
185 Expect.equals(999, dt.milliseconds); 185 Expect.equals(999, dt.milliseconds);
186 dt = new Date.withTimeZone(2035, 1, 1, 0, 0, 0, 1, const TimeZone.utc()); 186 dt = new Date(2035, 1, 1, 0, 0, 0, 1, isUtc: true);
187 Expect.equals(SECONDS_YEAR_2035 * 1000 + 1, dt.value); 187 Expect.equals(SECONDS_YEAR_2035 * 1000 + 1, dt.value);
188 dt = new Date.withTimeZone(2034, 12, 31, 23, 59, 59, 999, 188 dt = new Date(2034, 12, 31, 23, 59, 59, 999, isUtc: true);
189 const TimeZone.utc());
190 Expect.equals(SECONDS_YEAR_2035 * 1000 - 1, dt.value); 189 Expect.equals(SECONDS_YEAR_2035 * 1000 - 1, dt.value);
191 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 + 1, new TimeZone.local()); 190 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 + 1);
192 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) || 191 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
193 (2034 == dt.year && 12 == dt.month && 31 == dt.day)); 192 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
194 Expect.equals(0, dt.seconds); 193 Expect.equals(0, dt.seconds);
195 Expect.equals(1, dt.milliseconds); 194 Expect.equals(1, dt.milliseconds);
196 Date dt2 = new Date.withTimeZone( 195 Date dt2 = new Date(
197 dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds, 196 dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds,
198 dt.milliseconds, new TimeZone.local()); 197 dt.milliseconds);
199 Expect.equals(dt.value, dt2.value); 198 Expect.equals(dt.value, dt2.value);
200 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 - 1, new TimeZone.local()); 199 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 - 1);
201 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) || 200 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
202 (2034 == dt.year && 12 == dt.month && 31 == dt.day)); 201 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
203 Expect.equals(59, dt.seconds); 202 Expect.equals(59, dt.seconds);
204 Expect.equals(999, dt.milliseconds); 203 Expect.equals(999, dt.milliseconds);
205 dt2 = new Date.withTimeZone( 204 dt2 = new Date(
206 dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds, 205 dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds,
207 dt.milliseconds, new TimeZone.local()); 206 dt.milliseconds);
208 Expect.equals(dt.value, dt2.value); 207 Expect.equals(dt.value, dt2.value);
209 } 208 }
210 209
211 static void testUTCGetters() { 210 static void testUTCGetters() {
212 var dt = new Date.fromEpoch(1305140315000, const TimeZone.utc()); 211 var dt = new Date.fromEpoch(1305140315000, isUtc: true);
213 Expect.equals(2011, dt.year); 212 Expect.equals(2011, dt.year);
214 Expect.equals(5, dt.month); 213 Expect.equals(5, dt.month);
215 Expect.equals(11, dt.day); 214 Expect.equals(11, dt.day);
216 Expect.equals(18, dt.hours); 215 Expect.equals(18, dt.hours);
217 Expect.equals(58, dt.minutes); 216 Expect.equals(58, dt.minutes);
218 Expect.equals(35, dt.seconds); 217 Expect.equals(35, dt.seconds);
219 Expect.equals(0, dt.milliseconds); 218 Expect.equals(0, dt.milliseconds);
220 Expect.equals(true, const TimeZone.utc() == dt.timeZone); 219 Expect.equals(true, dt.isUtc());
221 Expect.equals(1305140315000, dt.value); 220 Expect.equals(1305140315000, dt.value);
222 dt = new Date.fromEpoch(-9999999, const TimeZone.utc()); 221 dt = new Date.fromEpoch(-9999999, isUtc: true);
223 Expect.equals(1969, dt.year); 222 Expect.equals(1969, dt.year);
224 Expect.equals(12, dt.month); 223 Expect.equals(12, dt.month);
225 Expect.equals(31, dt.day); 224 Expect.equals(31, dt.day);
226 Expect.equals(21, dt.hours); 225 Expect.equals(21, dt.hours);
227 Expect.equals(13, dt.minutes); 226 Expect.equals(13, dt.minutes);
228 Expect.equals(20, dt.seconds); 227 Expect.equals(20, dt.seconds);
229 Expect.equals(1, dt.milliseconds); 228 Expect.equals(1, dt.milliseconds);
230 } 229 }
231 230
232 static void testLocalGetters() { 231 static void testLocalGetters() {
233 var dt1 = new Date.fromEpoch(1305140315000, new TimeZone.local()); 232 var dt1 = new Date.fromEpoch(1305140315000);
234 var dt2 = new Date.withTimeZone(dt1.year, dt1.month, dt1.day, 233 var dt2 = new Date(dt1.year, dt1.month, dt1.day,
235 dt1.hours, dt1.minutes, dt1.seconds, 234 dt1.hours, dt1.minutes, dt1.seconds,
236 dt1.milliseconds, 235 dt1.milliseconds,
237 const TimeZone.utc()); 236 isUtc: true);
238 Duration zoneOffset = dt1.difference(dt2); 237 Duration zoneOffset = dt1.difference(dt2);
239 Expect.equals(true, zoneOffset.inDays == 0); 238 Expect.equals(true, zoneOffset.inDays == 0);
240 Expect.equals(true, zoneOffset.inHours.abs() <= 12); 239 Expect.equals(true, zoneOffset.inHours.abs() <= 12);
241 Expect.equals(dt1.year, dt2.year); 240 Expect.equals(dt1.year, dt2.year);
242 Expect.equals(dt1.month, dt2.month); 241 Expect.equals(dt1.month, dt2.month);
243 Expect.equals(true, (dt1.day - dt2.day).abs() <= 1); 242 Expect.equals(true, (dt1.day - dt2.day).abs() <= 1);
244 Expect.equals(true, dt1.hours < 24); 243 Expect.equals(true, dt1.hours < 24);
245 // There are timezones with 0.5 or 0.25 hour offsets. 244 // There are timezones with 0.5 or 0.25 hour offsets.
246 Expect.equals(true, 245 Expect.equals(true,
247 (dt1.minutes == dt2.minutes) || 246 (dt1.minutes == dt2.minutes) ||
248 ((dt1.minutes - dt2.minutes).abs() == 30) || 247 ((dt1.minutes - dt2.minutes).abs() == 30) ||
249 ((dt1.minutes - dt2.minutes).abs() == 15)); 248 ((dt1.minutes - dt2.minutes).abs() == 15));
250 Expect.equals(dt1.seconds, dt2.seconds); 249 Expect.equals(dt1.seconds, dt2.seconds);
251 Expect.equals(dt1.milliseconds, dt2.milliseconds); 250 Expect.equals(dt1.milliseconds, dt2.milliseconds);
252 } 251 }
253 252
254 static void testConstructors() { 253 static void testConstructors() {
255 var dt1 = new Date.fromEpoch(1305140315000, new TimeZone.local()); 254 var dt1 = new Date.fromEpoch(1305140315000);
256 var dt3 = new Date(dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 255 var dt3 = new Date(dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
257 dt1.seconds, dt1.milliseconds); 256 dt1.seconds, dt1.milliseconds);
258 Expect.equals(dt1.value, dt3.value); 257 Expect.equals(dt1.value, dt3.value);
259 Expect.equals(true, dt1 == dt3); 258 Expect.equals(true, dt1 == dt3);
260 dt3 = new Date.withTimeZone( 259 dt3 = new Date(
261 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 260 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
262 dt1.seconds, dt1.milliseconds, new TimeZone.local()); 261 dt1.seconds, dt1.milliseconds);
263 Expect.equals(dt1.value, dt3.value); 262 Expect.equals(dt1.value, dt3.value);
264 Expect.equals(true, dt1 == dt3); 263 Expect.equals(true, dt1 == dt3);
265 dt3 = new Date.withTimeZone(2011, 5, 11, 18, 58, 35, 0, 264 dt3 = new Date(2011, 5, 11, 18, 58, 35, 0, isUtc: true);
266 const TimeZone.utc());
267 Expect.equals(dt1.value, dt3.value); 265 Expect.equals(dt1.value, dt3.value);
268 Expect.equals(false, dt1 == dt3); 266 Expect.equals(true, dt1 == dt3);
269 var dt2 = dt1.changeTimeZone(new TimeZone.local()); 267 var dt2 = dt1.toLocal();
270 dt3 = new Date.withTimeZone(2011, 5, dt1.day, 268 dt3 = new Date(2011, 5, dt1.day, dt1.hours, dt1.minutes, 35, 0);
271 dt1.hours, dt1.minutes, 35, 0,
272 new TimeZone.local());
273 Expect.equals(dt2.value, dt3.value); 269 Expect.equals(dt2.value, dt3.value);
274 Expect.equals(true, dt2 == dt3); 270 Expect.equals(true, dt2 == dt3);
275 dt1 = new Date.fromEpoch(-9999999, const TimeZone.utc()); 271 dt1 = new Date.fromEpoch(-9999999, isUtc: true);
276 dt3 = new Date.withTimeZone( 272 dt3 = new Date(
277 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 273 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
278 dt1.seconds, dt1.milliseconds, const TimeZone.utc()); 274 dt1.seconds, dt1.milliseconds, isUtc: true);
279 Expect.equals(dt1.value, dt3.value); 275 Expect.equals(dt1.value, dt3.value);
280 dt3 = new Date.withTimeZone(99, 1, 2, 10, 11, 12, 0, 276 dt3 = new Date(99, 1, 2, 10, 11, 12, 0, isUtc: true);
281 const TimeZone.utc());
282 Expect.equals(99, dt3.year); 277 Expect.equals(99, dt3.year);
283 Expect.equals(1, dt3.month); 278 Expect.equals(1, dt3.month);
284 Expect.equals(2, dt3.day); 279 Expect.equals(2, dt3.day);
285 Expect.equals(10, dt3.hours); 280 Expect.equals(10, dt3.hours);
286 Expect.equals(11, dt3.minutes); 281 Expect.equals(11, dt3.minutes);
287 Expect.equals(12, dt3.seconds); 282 Expect.equals(12, dt3.seconds);
288 Expect.equals(0, dt3.milliseconds); 283 Expect.equals(0, dt3.milliseconds);
289 Expect.equals(true, dt3.isUtc()); 284 Expect.equals(true, dt3.isUtc());
290 } 285 }
291 286
292 static void testChangeTimeZone() { 287 static void testChangeTimeZone() {
293 var dt1 = new Date.fromEpoch(1305140315000, new TimeZone.local()); 288 var dt1 = new Date.fromEpoch(1305140315000);
294 var dt2 = dt1.changeTimeZone(const TimeZone.utc()); 289 var dt2 = dt1.toUtc();
295 Expect.equals(dt1.value, dt2.value); 290 Expect.equals(dt1.value, dt2.value);
296 var dt3 = new Date.fromEpoch(1305140315000, const TimeZone.utc()); 291 var dt3 = new Date.fromEpoch(1305140315000, isUtc: true);
297 Expect.equals(dt1.value, dt3.value); 292 Expect.equals(dt1.value, dt3.value);
298 Expect.equals(dt2.year, dt3.year); 293 Expect.equals(dt2.year, dt3.year);
299 Expect.equals(dt2.month, dt3.month); 294 Expect.equals(dt2.month, dt3.month);
300 Expect.equals(dt2.day, dt3.day); 295 Expect.equals(dt2.day, dt3.day);
301 Expect.equals(dt2.hours, dt3.hours); 296 Expect.equals(dt2.hours, dt3.hours);
302 Expect.equals(dt2.minutes, dt3.minutes); 297 Expect.equals(dt2.minutes, dt3.minutes);
303 Expect.equals(dt2.seconds, dt3.seconds); 298 Expect.equals(dt2.seconds, dt3.seconds);
304 Expect.equals(dt2.milliseconds, dt3.milliseconds); 299 Expect.equals(dt2.milliseconds, dt3.milliseconds);
305 var dt4 = dt3.changeTimeZone(new TimeZone.local()); 300 var dt4 = dt3.toLocal();
306 Expect.equals(dt1.year, dt4.year); 301 Expect.equals(dt1.year, dt4.year);
307 Expect.equals(dt1.month, dt4.month); 302 Expect.equals(dt1.month, dt4.month);
308 Expect.equals(dt1.day, dt4.day); 303 Expect.equals(dt1.day, dt4.day);
309 Expect.equals(dt1.hours, dt4.hours); 304 Expect.equals(dt1.hours, dt4.hours);
310 Expect.equals(dt1.minutes, dt4.minutes); 305 Expect.equals(dt1.minutes, dt4.minutes);
311 Expect.equals(dt1.seconds, dt4.seconds); 306 Expect.equals(dt1.seconds, dt4.seconds);
312 Expect.equals(dt1.milliseconds, dt4.milliseconds); 307 Expect.equals(dt1.milliseconds, dt4.milliseconds);
313 } 308 }
314 309
315 static void testSubAdd() { 310 static void testSubAdd() {
316 var dt1 = new Date.fromEpoch(1305140315000, const TimeZone.utc()); 311 var dt1 = new Date.fromEpoch(1305140315000, isUtc: true);
317 var dt2 = dt1.add(new Duration(milliseconds: 312 var dt2 = dt1.add(new Duration(milliseconds:
318 3 * Duration.MILLISECONDS_PER_SECOND + 5)); 313 3 * Duration.MILLISECONDS_PER_SECOND + 5));
319 Expect.equals(dt1.year, dt2.year); 314 Expect.equals(dt1.year, dt2.year);
320 Expect.equals(dt1.month, dt2.month); 315 Expect.equals(dt1.month, dt2.month);
321 Expect.equals(dt1.day, dt2.day); 316 Expect.equals(dt1.day, dt2.day);
322 Expect.equals(dt1.hours, dt2.hours); 317 Expect.equals(dt1.hours, dt2.hours);
323 Expect.equals(dt1.minutes, dt2.minutes); 318 Expect.equals(dt1.minutes, dt2.minutes);
324 Expect.equals(dt1.seconds + 3, dt2.seconds); 319 Expect.equals(dt1.seconds + 3, dt2.seconds);
325 Expect.equals(dt1.milliseconds + 5, dt2.milliseconds); 320 Expect.equals(dt1.milliseconds + 5, dt2.milliseconds);
326 var dt3 = dt2.subtract(new Duration(milliseconds: 321 var dt3 = dt2.subtract(new Duration(milliseconds:
327 3 * Duration.MILLISECONDS_PER_SECOND + 5)); 322 3 * Duration.MILLISECONDS_PER_SECOND + 5));
328 Expect.equals(true, dt1 == dt3); 323 Expect.equals(true, dt1 == dt3);
329 Expect.equals(false, dt1 == dt2); 324 Expect.equals(false, dt1 == dt2);
330 } 325 }
331 326
332 static void testDateStrings() { 327 static void testDateStrings() {
333 // TODO(floitsch): Clean up the Date API that deals with strings. 328 // TODO(floitsch): Clean up the Date API that deals with strings.
334 var dt1 = new Date.fromString("2011-05-11 18:58:35Z"); 329 var dt1 = new Date.fromString("2011-05-11 18:58:35Z");
335 Expect.equals(1305140315000, dt1.value); 330 Expect.equals(1305140315000, dt1.value);
336 Expect.isTrue(dt1.isUtc()); 331 Expect.isTrue(dt1.isUtc());
337 dt1 = new Date.fromString("20110511 18:58:35z"); 332 dt1 = new Date.fromString("20110511 18:58:35z");
338 Expect.equals(1305140315000, dt1.value); 333 Expect.equals(1305140315000, dt1.value);
339 Expect.isTrue(dt1.isUtc()); 334 Expect.isTrue(dt1.isUtc());
340 dt1 = new Date.fromString("+20110511 18:58:35z"); 335 dt1 = new Date.fromString("+20110511 18:58:35z");
341 Expect.equals(1305140315000, dt1.value); 336 Expect.equals(1305140315000, dt1.value);
342 Expect.isTrue(dt1.isUtc()); 337 Expect.isTrue(dt1.isUtc());
343 var str = dt1.toString(); 338 var str = dt1.toString();
344 var dt2 = new Date.fromString(str); 339 var dt2 = new Date.fromString(str);
345 Expect.equals(true, dt1 == dt2); 340 Expect.equals(true, dt1 == dt2);
346 var dt3 = dt1.changeTimeZone(const TimeZone.utc()); 341 var dt3 = dt1.toUtc();
347 str = dt3.toString(); 342 str = dt3.toString();
348 Expect.equals("2011-05-11 18:58:35.000Z", str); 343 Expect.equals("2011-05-11 18:58:35.000Z", str);
349 var dt4 = new Date.fromString("-1234-01-01 00:00:00Z"); 344 var dt4 = new Date.fromString("-1234-01-01 00:00:00Z");
350 Expect.equals(-1234, dt4.year); 345 Expect.equals(-1234, dt4.year);
351 Expect.equals(1, dt4.month); 346 Expect.equals(1, dt4.month);
352 Expect.equals(1, dt4.day); 347 Expect.equals(1, dt4.day);
353 Expect.equals(0, dt4.hours); 348 Expect.equals(0, dt4.hours);
354 Expect.equals(0, dt4.minutes); 349 Expect.equals(0, dt4.minutes);
355 Expect.equals(0, dt4.seconds); 350 Expect.equals(0, dt4.seconds);
356 Expect.equals(0, dt4.milliseconds); 351 Expect.equals(0, dt4.milliseconds);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 Expect.equals(9, dt1.minutes); 491 Expect.equals(9, dt1.minutes);
497 Expect.equals(9, dt1.seconds); 492 Expect.equals(9, dt1.seconds);
498 Expect.equals(9, dt1.milliseconds); 493 Expect.equals(9, dt1.milliseconds);
499 Expect.equals(true, dt1.isUtc()); 494 Expect.equals(true, dt1.isUtc());
500 } 495 }
501 496
502 static void testWeekday() { 497 static void testWeekday() {
503 // 2011-10-06 is Summertime. 498 // 2011-10-06 is Summertime.
504 var d = new Date(2011, 10, 6, 0, 45, 37, 0); 499 var d = new Date(2011, 10, 6, 0, 45, 37, 0);
505 Expect.equals(Date.THU, d.weekday); 500 Expect.equals(Date.THU, d.weekday);
506 d = new Date.withTimeZone(2011, 10, 6, 0, 45, 37, 0, const TimeZone.utc()); 501 d = new Date(2011, 10, 6, 0, 45, 37, 0, isUtc: true);
507 Expect.equals(Date.THU, d.weekday); 502 Expect.equals(Date.THU, d.weekday);
508 d = new Date(2011, 10, 5, 23, 45, 37, 0); 503 d = new Date(2011, 10, 5, 23, 45, 37, 0);
509 Expect.equals(Date.WED, d.weekday); 504 Expect.equals(Date.WED, d.weekday);
510 d = new Date.withTimeZone(2011, 10, 5, 23, 45, 37, 0, const TimeZone.utc()); 505 d = new Date(2011, 10, 5, 23, 45, 37, 0, isUtc: true);
511 Expect.equals(Date.WED, d.weekday); 506 Expect.equals(Date.WED, d.weekday);
512 // 1970-01-01 is Wintertime. 507 // 1970-01-01 is Wintertime.
513 d = new Date(1970, 1, 1, 0, 0, 0, 1); 508 d = new Date(1970, 1, 1, 0, 0, 0, 1);
514 Expect.equals(Date.THU, d.weekday); 509 Expect.equals(Date.THU, d.weekday);
515 d = new Date.withTimeZone(1970, 1, 1, 0, 0, 0, 1, const TimeZone.utc()); 510 d = new Date(1970, 1, 1, 0, 0, 0, 1, isUtc: true);
516 Expect.equals(Date.THU, d.weekday); 511 Expect.equals(Date.THU, d.weekday);
517 d = new Date.withTimeZone(1969, 12, 31, 23, 59, 59, 999, 512 d = new Date(1969, 12, 31, 23, 59, 59, 999, isUtc: true);
518 const TimeZone.utc());
519 Expect.equals(Date.WED, d.weekday); 513 Expect.equals(Date.WED, d.weekday);
520 d = new Date(1969, 12, 31, 23, 59, 59, 999); 514 d = new Date(1969, 12, 31, 23, 59, 59, 999);
521 Expect.equals(Date.WED, d.weekday); 515 Expect.equals(Date.WED, d.weekday);
522 d = new Date(2011, 10, 4, 23, 45, 37, 0); 516 d = new Date(2011, 10, 4, 23, 45, 37, 0);
523 Expect.equals(Date.TUE, d.weekday); 517 Expect.equals(Date.TUE, d.weekday);
524 d = new Date(2011, 10, 3, 23, 45, 37, 0); 518 d = new Date(2011, 10, 3, 23, 45, 37, 0);
525 Expect.equals(Date.MON, d.weekday); 519 Expect.equals(Date.MON, d.weekday);
526 d = new Date(2011, 10, 2, 23, 45, 37, 0); 520 d = new Date(2011, 10, 2, 23, 45, 37, 0);
527 Expect.equals(Date.SUN, d.weekday); 521 Expect.equals(Date.SUN, d.weekday);
528 d = new Date(2011, 10, 1, 23, 45, 37, 0); 522 d = new Date(2011, 10, 1, 23, 45, 37, 0);
(...skipping 13 matching lines...) Expand all
542 testDateStrings(); 536 testDateStrings();
543 testEquivalentYears(); 537 testEquivalentYears();
544 testFarAwayDates(); 538 testFarAwayDates();
545 testWeekday(); 539 testWeekday();
546 } 540 }
547 } 541 }
548 542
549 main() { 543 main() {
550 DateTest.testMain(); 544 DateTest.testMain();
551 } 545 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698