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

Side by Side Diff: pkg/intl/test/date_time_format_test_core.dart

Issue 92333002: Retry date comparison to avoid a rare flake that might be associated with DST (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't suppress the error, print more information about it Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Tests the DateFormat library in dart. This file contains core tests that 6 * Tests the DateFormat library in dart. This file contains core tests that
7 * are run regardless of where the locale data is found, so it doesn't expect to 7 * are run regardless of where the locale data is found, so it doesn't expect to
8 * be run on its own, but rather to be imported and run from another test file. 8 * be run on its own, but rather to be imported and run from another test file.
9 */ 9 */
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 } 138 }
139 139
140 testRoundTripParsing(String localeName, DateTime date) { 140 testRoundTripParsing(String localeName, DateTime date) {
141 // In order to test parsing, we can't just read back the date, because 141 // In order to test parsing, we can't just read back the date, because
142 // printing in most formats loses information. But we can test that 142 // printing in most formats loses information. But we can test that
143 // what we parsed back prints the same as what we originally printed. 143 // what we parsed back prints the same as what we originally printed.
144 // At least in most cases. In some cases, we can't even do that. e.g. 144 // At least in most cases. In some cases, we can't even do that. e.g.
145 // the skeleton WEEKDAY can't be reconstructed at all, and YEAR_MONTH 145 // the skeleton WEEKDAY can't be reconstructed at all, and YEAR_MONTH
146 // formats don't give us enough information to construct a valid date. 146 // formats don't give us enough information to construct a valid date.
147 var badSkeletons = [ 147 var badSkeletons = const [
148 DateFormat.ABBR_WEEKDAY, 148 DateFormat.ABBR_WEEKDAY,
149 DateFormat.WEEKDAY, 149 DateFormat.WEEKDAY,
150 DateFormat.QUARTER, 150 DateFormat.QUARTER,
151 DateFormat.ABBR_QUARTER, 151 DateFormat.ABBR_QUARTER,
152 DateFormat.YEAR, 152 DateFormat.YEAR,
153 DateFormat.YEAR_NUM_MONTH, 153 DateFormat.YEAR_NUM_MONTH,
154 DateFormat.YEAR_ABBR_MONTH, 154 DateFormat.YEAR_ABBR_MONTH,
155 DateFormat.YEAR_MONTH, 155 DateFormat.YEAR_MONTH,
156 DateFormat.MONTH_WEEKDAY_DAY, 156 DateFormat.MONTH_WEEKDAY_DAY,
157 DateFormat.NUM_MONTH_WEEKDAY_DAY, 157 DateFormat.NUM_MONTH_WEEKDAY_DAY,
158 DateFormat.ABBR_MONTH_WEEKDAY_DAY]; 158 DateFormat.ABBR_MONTH_WEEKDAY_DAY];
159 var originalTime = new DateTime.now();
160 var originalTimeZoneOffset = date.timeZoneOffset;
161 var originalTimeZoneName = date.timeZoneName;
159 for(int i = 0; i < formatsToTest.length; i++) { 162 for(int i = 0; i < formatsToTest.length; i++) {
160 var skeleton = formatsToTest[i]; 163 var skeleton = formatsToTest[i];
161 if (!badSkeletons.any((x) => x == skeleton)) { 164 if (!badSkeletons.any((x) => x == skeleton)) {
162 var format = new DateFormat(skeleton, localeName); 165 var format = new DateFormat(skeleton, localeName);
163 var actualResult = format.format(date); 166 var actualResult = format.format(date);
164 var parsed = format.parse(actualResult); 167 var parsed = format.parse(actualResult);
165 var thenPrintAgain = format.format(parsed); 168 var thenPrintAgain = format.format(parsed);
169 // We've seen a case where this failed in a way that seemed like a time
170 // zone shifting or some other strange behaviour that caused an off by
171 // one error in the date. Check for this and print out as much information
172 // as possible if it occurs again.
173 if (thenPrintAgain != actualResult) {
174 print("Date mismatch!");
175 print(" Expected $actualResult");
176 print(" Got $thenPrintAgain");
177 print(" Original date = $date");
178 print(" Original ms = ${date.millisecondsSinceEpoch}");
179 print(" Parsed back to $parsed");
180 print(" Parsed ms = ${parsed.millisecondsSinceEpoch}");
181 print(" Original tz = $originalTimeZoneOffset");
182 print(" Current tz name = $originalTimeZoneName");
183 print(" Current tz = ${parsed.timeZoneOffset}");
184 print(" Current tz name = ${parsed.timeZoneName}");
185 print(" Start time = $originalTime");
186 print(" Current time ${new DateTime.now()}");
187 }
166 expect(thenPrintAgain, equals(actualResult)); 188 expect(thenPrintAgain, equals(actualResult));
167 } 189 }
168 } 190 }
169 } 191 }
170 192
171 /** A shortcut for returning all the locales we have available.*/ 193 /** A shortcut for returning all the locales we have available.*/
172 List<String> allLocales() => DateFormat.allLocalesWithSymbols(); 194 List<String> allLocales() => DateFormat.allLocalesWithSymbols();
173 195
174 Function _subsetFunc; 196 Function _subsetFunc;
175 197
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 var f = new DateFormat("D"); 417 var f = new DateFormat("D");
396 var dates = generateDates(2012, 1); 418 var dates = generateDates(2012, 1);
397 var nonLeapDates = generateDates(2013, 0); 419 var nonLeapDates = generateDates(2013, 0);
398 verifyOrdinals(dates); 420 verifyOrdinals(dates);
399 verifyOrdinals(nonLeapDates); 421 verifyOrdinals(nonLeapDates);
400 // Check one hard-coded just to be on the safe side. 422 // Check one hard-coded just to be on the safe side.
401 var aDate = new DateTime(2012, 4, 27, 13, 58, 59, 012); 423 var aDate = new DateTime(2012, 4, 27, 13, 58, 59, 012);
402 expect(f.format(aDate), "118"); 424 expect(f.format(aDate), "118");
403 }); 425 });
404 } 426 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698