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

Side by Side Diff: test/dart_codegen/expect/core/date_time.dart

Issue 963593002: Disable formatting and add new-lines to make tests faster. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 part of dart.core; 1 part of dart.core;
2 2 class DateTime implements Comparable {static const int MONDAY = 1;
3 class DateTime implements Comparable { 3 static const int TUESDAY = 2;
4 static const int MONDAY = 1; 4 static const int WEDNESDAY = 3;
5 static const int TUESDAY = 2; 5 static const int THURSDAY = 4;
6 static const int WEDNESDAY = 3; 6 static const int FRIDAY = 5;
7 static const int THURSDAY = 4; 7 static const int SATURDAY = 6;
8 static const int FRIDAY = 5; 8 static const int SUNDAY = 7;
9 static const int SATURDAY = 6; 9 static const int DAYS_PER_WEEK = 7;
10 static const int SUNDAY = 7; 10 static const int JANUARY = 1;
11 static const int DAYS_PER_WEEK = 7; 11 static const int FEBRUARY = 2;
12 static const int JANUARY = 1; 12 static const int MARCH = 3;
13 static const int FEBRUARY = 2; 13 static const int APRIL = 4;
14 static const int MARCH = 3; 14 static const int MAY = 5;
15 static const int APRIL = 4; 15 static const int JUNE = 6;
16 static const int MAY = 5; 16 static const int JULY = 7;
17 static const int JUNE = 6; 17 static const int AUGUST = 8;
18 static const int JULY = 7; 18 static const int SEPTEMBER = 9;
19 static const int AUGUST = 8; 19 static const int OCTOBER = 10;
20 static const int SEPTEMBER = 9; 20 static const int NOVEMBER = 11;
21 static const int OCTOBER = 10; 21 static const int DECEMBER = 12;
22 static const int NOVEMBER = 11; 22 static const int MONTHS_PER_YEAR = 12;
23 static const int DECEMBER = 12; 23 final int millisecondsSinceEpoch;
24 static const int MONTHS_PER_YEAR = 12; 24 final bool isUtc;
25 final int millisecondsSinceEpoch; 25 DateTime(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, i nt second = 0, int millisecond = 0]) : this._internal(year, month, day, hour, mi nute, second, millisecond, false);
26 final bool isUtc; 26 DateTime.utc(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0]) : this._internal(year, month, day, hour , minute, second, millisecond, true);
27 DateTime(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, 27 DateTime.now() : this._now();
28 int second = 0, int millisecond = 0]) 28 static DateTime parse(String formattedString) {
29 : this._internal( 29 final RegExp re = new RegExp(r'^([+-]?\d{4,6})-?(\d\d)-?(\d\d)' r'(?:[ T](\d\d )(?::?(\d\d)(?::?(\d\d)(.\d{1,6})?)?)?' r'( ?[zZ]| ?([-+])(\d\d)(?::?(\d\d))?)?) ?$');
30 year, month, day, hour, minute, second, millisecond, false); 30 Match match = re.firstMatch(formattedString);
31 DateTime.utc(int year, [int month = 1, int day = 1, int hour = 0, 31 if (match != null) {
32 int minute = 0, int second = 0, int millisecond = 0]) 32 int parseIntOrZero(String matched) {
33 : this._internal( 33 if (matched == null) return 0;
34 year, month, day, hour, minute, second, millisecond, true); 34 return int.parse(matched);
35 DateTime.now() : this._now(); 35 }
36 static DateTime parse(String formattedString) { 36 double parseDoubleOrZero(String matched) {
37 final RegExp re = new RegExp( 37 if (matched == null) return 0.0;
38 r'^([+-]?\d{4,6})-?(\d\d)-?(\d\d)' r'(?:[ T](\d\d)(?::?(\d\d)(?::?(\d\d) (.\d{1,6})?)?)?' r'( ?[zZ]| ?([-+])(\d\d)(?::?(\d\d))?)?)?$'); 38 return double.parse(matched);
39 Match match = re.firstMatch(formattedString); 39 }
40 if (match != null) { 40 int years = int.parse(match[1]);
41 int parseIntOrZero(String matched) { 41 int month = int.parse(match[2]);
42 if (matched == null) return 0; 42 int day = int.parse(match[3]);
43 return int.parse(matched); 43 int hour = parseIntOrZero(match[4]);
44 } 44 int minute = parseIntOrZero(match[5]);
45 double parseDoubleOrZero(String matched) { 45 int second = parseIntOrZero(match[6]);
46 if (matched == null) return 0.0; 46 bool addOneMillisecond = false;
47 return double.parse(matched); 47 int millisecond = (parseDoubleOrZero(match[7]) * 1000).round();
48 } 48 if (millisecond == 1000) {
49 int years = int.parse(match[1]); 49 addOneMillisecond = true;
50 int month = int.parse(match[2]); 50 millisecond = 999;
51 int day = int.parse(match[3]); 51 }
52 int hour = parseIntOrZero(match[4]); 52 bool isUtc = false;
53 int minute = parseIntOrZero(match[5]); 53 if (match[8] != null) {
54 int second = parseIntOrZero(match[6]); 54 isUtc = true;
55 bool addOneMillisecond = false; 55 if (match[9] != null) {
56 int millisecond = (parseDoubleOrZero(match[7]) * 1000).round(); 56 int sign = (match[9] == '-') ? -1 : 1;
57 if (millisecond == 1000) { 57 int hourDifference = int.parse(match[10]);
58 addOneMillisecond = true; 58 int minuteDifference = parseIntOrZero(match[11]);
59 millisecond = 999; 59 minuteDifference += 60 * hourDifference;
60 } 60 minute -= sign * minuteDifference;
61 bool isUtc = false;
62 if (match[8] != null) {
63 isUtc = true;
64 if (match[9] != null) {
65 int sign = (match[9] == '-') ? -1 : 1;
66 int hourDifference = int.parse(match[10]);
67 int minuteDifference = parseIntOrZero(match[11]);
68 minuteDifference += 60 * hourDifference;
69 minute -= sign * minuteDifference;
70 } 61 }
71 } 62 }
72 int millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch( 63 int millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch(years, month, day, hour, minute, second, millisecond, isUtc);
73 years, month, day, hour, minute, second, millisecond, isUtc); 64 if (millisecondsSinceEpoch == null) {
74 if (millisecondsSinceEpoch == null) { 65 throw new FormatException("Time out of range", formattedString);
75 throw new FormatException("Time out of range", formattedString); 66 }
76 } 67 if (addOneMillisecond) millisecondsSinceEpoch++;
77 if (addOneMillisecond) millisecondsSinceEpoch++; 68 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUt c: isUtc);
78 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, 69 }
79 isUtc: isUtc); 70 else {
80 } else { 71 throw new FormatException("Invalid date format", formattedString);
81 throw new FormatException("Invalid date format", formattedString); 72 }
82 } 73 }
83 } 74 static const int _MAX_MILLISECONDS_SINCE_EPOCH = 8640000000000000;
84 static const int _MAX_MILLISECONDS_SINCE_EPOCH = 8640000000000000; 75 DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, {
85 DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, 76 bool isUtc : false}
86 {bool isUtc: false}) 77 ) : this.millisecondsSinceEpoch = millisecondsSinceEpoch, this.isUtc = isUtc {
87 : this.millisecondsSinceEpoch = millisecondsSinceEpoch, 78 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH) {
88 this.isUtc = isUtc { 79 throw new ArgumentError(millisecondsSinceEpoch);
89 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH) { 80 }
90 throw new ArgumentError(millisecondsSinceEpoch); 81 if (isUtc == null) throw new ArgumentError(isUtc);
91 } 82 }
92 if (isUtc == null) throw new ArgumentError(isUtc); 83 bool operator ==(other) {
93 } 84 if (!(other is DateTime)) return false;
94 bool operator ==(other) { 85 return (millisecondsSinceEpoch == other.millisecondsSinceEpoch && isUtc == ot her.isUtc);
95 if (!(other is DateTime)) return false; 86 }
96 return (millisecondsSinceEpoch == other.millisecondsSinceEpoch && 87 bool isBefore(DateTime other) {
97 isUtc == other.isUtc); 88 return millisecondsSinceEpoch < other.millisecondsSinceEpoch;
98 } 89 }
99 bool isBefore(DateTime other) { 90 bool isAfter(DateTime other) {
100 return millisecondsSinceEpoch < other.millisecondsSinceEpoch; 91 return millisecondsSinceEpoch > other.millisecondsSinceEpoch;
101 } 92 }
102 bool isAfter(DateTime other) { 93 bool isAtSameMomentAs(DateTime other) {
103 return millisecondsSinceEpoch > other.millisecondsSinceEpoch; 94 return millisecondsSinceEpoch == other.millisecondsSinceEpoch;
104 } 95 }
105 bool isAtSameMomentAs(DateTime other) { 96 int compareTo(DateTime other) => millisecondsSinceEpoch.compareTo(other.millise condsSinceEpoch);
106 return millisecondsSinceEpoch == other.millisecondsSinceEpoch; 97 int get hashCode => millisecondsSinceEpoch;
107 } 98 DateTime toLocal() {
108 int compareTo(DateTime other) => 99 if (isUtc) {
109 millisecondsSinceEpoch.compareTo(other.millisecondsSinceEpoch); 100 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUtc : false);
110 int get hashCode => millisecondsSinceEpoch; 101 }
111 DateTime toLocal() { 102 return this;
112 if (isUtc) { 103 }
113 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, 104 DateTime toUtc() {
114 isUtc: false); 105 if (isUtc) return this;
115 } 106 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUtc: true);
116 return this; 107 }
117 } 108 static String _fourDigits(int n) {
118 DateTime toUtc() { 109 int absN = n.abs();
119 if (isUtc) return this; 110 String sign = n < 0 ? "-" : "";
120 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, 111 if (absN >= 1000) return "$n";
121 isUtc: true); 112 if (absN >= 100) return "${sign}
122 } 113 0$absN";
123 static String _fourDigits(int n) { 114 if (absN >= 10) return "${sign}
124 int absN = n.abs(); 115 00$absN";
125 String sign = n < 0 ? "-" : ""; 116 return "${sign}
126 if (absN >= 1000) return "$n"; 117 000$absN";
127 if (absN >= 100) return "${sign}0$absN"; 118 }
128 if (absN >= 10) return "${sign}00$absN"; 119 static String _sixDigits(int n) {
129 return "${sign}000$absN"; 120 assert (n < -9999 || n > 9999); int absN = n.abs();
130 } 121 String sign = n < 0 ? "-" : "+";
131 static String _sixDigits(int n) { 122 if (absN >= 100000) return "$sign$absN";
132 assert(n < -9999 || n > 9999); 123 return "${sign}
133 int absN = n.abs(); 124 0$absN";
134 String sign = n < 0 ? "-" : "+"; 125 }
135 if (absN >= 100000) return "$sign$absN"; 126 static String _threeDigits(int n) {
136 return "${sign}0$absN"; 127 if (n >= 100) return "${n}
137 } 128 ";
138 static String _threeDigits(int n) { 129 if (n >= 10) return "0${n}
139 if (n >= 100) return "${n}"; 130 ";
140 if (n >= 10) return "0${n}"; 131 return "00${n}
141 return "00${n}"; 132 ";
142 } 133 }
143 static String _twoDigits(int n) { 134 static String _twoDigits(int n) {
144 if (n >= 10) return "${n}"; 135 if (n >= 10) return "${n}
145 return "0${n}"; 136 ";
146 } 137 return "0${n}
147 String toString() { 138 ";
148 String y = _fourDigits(year); 139 }
149 String m = _twoDigits(month); 140 String toString() {
150 String d = _twoDigits(day); 141 String y = _fourDigits(year);
151 String h = _twoDigits(hour); 142 String m = _twoDigits(month);
152 String min = _twoDigits(minute); 143 String d = _twoDigits(day);
153 String sec = _twoDigits(second); 144 String h = _twoDigits(hour);
154 String ms = _threeDigits(millisecond); 145 String min = _twoDigits(minute);
155 if (isUtc) { 146 String sec = _twoDigits(second);
156 return "$y-$m-$d $h:$min:$sec.${ms}Z"; 147 String ms = _threeDigits(millisecond);
157 } else { 148 if (isUtc) {
158 return "$y-$m-$d $h:$min:$sec.$ms"; 149 return "$y-$m-$d $h:$min:$sec.${ms}
159 } 150 Z";
160 } 151 }
161 String toIso8601String() { 152 else {
162 String y = 153 return "$y-$m-$d $h:$min:$sec.$ms";
163 (year >= -9999 && year <= 9999) ? _fourDigits(year) : _sixDigits(year); 154 }
164 String m = _twoDigits(month); 155 }
165 String d = _twoDigits(day); 156 String toIso8601String() {
166 String h = _twoDigits(hour); 157 String y = (year >= -9999 && year <= 9999) ? _fourDigits(year) : _sixDigits(year );
167 String min = _twoDigits(minute); 158 String m = _twoDigits(month);
168 String sec = _twoDigits(second); 159 String d = _twoDigits(day);
169 String ms = _threeDigits(millisecond); 160 String h = _twoDigits(hour);
170 if (isUtc) { 161 String min = _twoDigits(minute);
171 return "$y-$m-${d}T$h:$min:$sec.${ms}Z"; 162 String sec = _twoDigits(second);
172 } else { 163 String ms = _threeDigits(millisecond);
173 return "$y-$m-${d}T$h:$min:$sec.$ms"; 164 if (isUtc) {
174 } 165 return "$y-$m-${d}
175 } 166 T$h:$min:$sec.${ms}
176 DateTime add(Duration duration) { 167 Z";
177 int ms = millisecondsSinceEpoch; 168 }
178 return new DateTime.fromMillisecondsSinceEpoch(ms + duration.inMilliseconds, 169 else {
179 isUtc: isUtc); 170 return "$y-$m-${d}
180 } 171 T$h:$min:$sec.$ms";
181 DateTime subtract(Duration duration) { 172 }
182 int ms = millisecondsSinceEpoch; 173 }
183 return new DateTime.fromMillisecondsSinceEpoch(ms - duration.inMilliseconds, 174 DateTime add(Duration duration) {
184 isUtc: isUtc); 175 int ms = millisecondsSinceEpoch;
185 } 176 return new DateTime.fromMillisecondsSinceEpoch(ms + duration.inMilliseconds, is Utc: isUtc);
186 Duration difference(DateTime other) { 177 }
187 int ms = millisecondsSinceEpoch; 178 DateTime subtract(Duration duration) {
188 int otherMs = other.millisecondsSinceEpoch; 179 int ms = millisecondsSinceEpoch;
189 return new Duration(milliseconds: ms - otherMs); 180 return new DateTime.fromMillisecondsSinceEpoch(ms - duration.inMilliseconds, is Utc: isUtc);
190 } 181 }
191 DateTime._internal(int year, int month, int day, int hour, int minute, 182 Duration difference(DateTime other) {
192 int second, int millisecond, bool isUtc) 183 int ms = millisecondsSinceEpoch;
193 : this.isUtc = isUtc is bool ? isUtc : throw new ArgumentError(isUtc), 184 int otherMs = other.millisecondsSinceEpoch;
194 millisecondsSinceEpoch = checkInt(Primitives.valueFromDecomposedDate( 185 return new Duration(milliseconds: ms - otherMs);
195 year, month, day, hour, minute, second, millisecond, isUtc)); 186 }
196 DateTime._now() 187 DateTime._internal(int year, int month, int day, int hour, int minute, int seco nd, int millisecond, bool isUtc) : this.isUtc = isUtc is bool ? isUtc : throw ne w ArgumentError(isUtc), millisecondsSinceEpoch = checkInt(Primitives.valueFromDe composedDate(year, month, day, hour, minute, second, millisecond, isUtc));
197 : isUtc = false, 188 DateTime._now() : isUtc = false, millisecondsSinceEpoch = Primitives.dateNow();
198 millisecondsSinceEpoch = Primitives.dateNow(); 189 static int _brokenDownDateToMillisecondsSinceEpoch(int year, int month, int day , int hour, int minute, int second, int millisecond, bool isUtc) {
199 static int _brokenDownDateToMillisecondsSinceEpoch(int year, int month, 190 return ((__x0) => DDC$RT.cast(__x0, dynamic, int, "CastGeneral", """line 599, co lumn 12 of dart:core/date_time.dart: """, __x0 is int, true))(Primitives.valueFr omDecomposedDate(year, month, day, hour, minute, second, millisecond, isUtc));
200 int day, int hour, int minute, int second, int millisecond, bool isUtc) { 191 }
201 return ((__x0) => DDC$RT.cast(__x0, dynamic, int, "CastGeneral", 192 String get timeZoneName {
202 """line 599, column 12 of dart:core/date_time.dart: """, 193 if (isUtc) return "UTC";
203 __x0 is int, true))(Primitives.valueFromDecomposedDate( 194 return ((__x1) => DDC$RT.cast(__x1, dynamic, String, "CastGeneral", """line 609 , column 12 of dart:core/date_time.dart: """, __x1 is String, true))(Primitives. getTimeZoneName(this));
204 year, month, day, hour, minute, second, millisecond, isUtc)); 195 }
205 } 196 Duration get timeZoneOffset {
206 String get timeZoneName { 197 if (isUtc) return new Duration();
207 if (isUtc) return "UTC"; 198 return new Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this));
208 return ((__x1) => DDC$RT.cast(__x1, dynamic, String, "CastGeneral", 199 }
209 """line 609, column 12 of dart:core/date_time.dart: """, __x1 is String, 200 int get year => ((__x2) => DDC$RT.cast(__x2, dynamic, int, "CastGeneral", """li ne 633, column 19 of dart:core/date_time.dart: """, __x2 is int, true))(Primitiv es.getYear(this));
210 true))(Primitives.getTimeZoneName(this)); 201 int get month => ((__x3) => DDC$RT.cast(__x3, dynamic, int, "CastGeneral", """l ine 642, column 20 of dart:core/date_time.dart: """, __x3 is int, true))(Primiti ves.getMonth(this));
211 } 202 int get day => ((__x4) => DDC$RT.cast(__x4, dynamic, int, "CastGeneral", """lin e 650, column 18 of dart:core/date_time.dart: """, __x4 is int, true))(Primitive s.getDay(this));
212 Duration get timeZoneOffset { 203 int get hour => ((__x5) => DDC$RT.cast(__x5, dynamic, int, "CastGeneral", """li ne 658, column 19 of dart:core/date_time.dart: """, __x5 is int, true))(Primitiv es.getHours(this));
213 if (isUtc) return new Duration(); 204 int get minute => ((__x6) => DDC$RT.cast(__x6, dynamic, int, "CastGeneral", """ line 666, column 21 of dart:core/date_time.dart: """, __x6 is int, true))(Primit ives.getMinutes(this));
214 return new Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this)); 205 int get second => ((__x7) => DDC$RT.cast(__x7, dynamic, int, "CastGeneral", """ line 674, column 21 of dart:core/date_time.dart: """, __x7 is int, true))(Primit ives.getSeconds(this));
215 } 206 int get millisecond => ((__x8) => DDC$RT.cast(__x8, dynamic, int, "CastGeneral" , """line 682, column 26 of dart:core/date_time.dart: """, __x8 is int, true))(P rimitives.getMilliseconds(this));
216 int get year => ((__x2) => DDC$RT.cast(__x2, dynamic, int, "CastGeneral", 207 int get weekday => ((__x9) => DDC$RT.cast(__x9, dynamic, int, "CastGeneral", "" "line 695, column 22 of dart:core/date_time.dart: """, __x9 is int, true))(Primi tives.getWeekday(this));
217 """line 633, column 19 of dart:core/date_time.dart: """, __x2 is int, 208 }
218 true))(Primitives.getYear(this));
219 int get month => ((__x3) => DDC$RT.cast(__x3, dynamic, int, "CastGeneral",
220 """line 642, column 20 of dart:core/date_time.dart: """, __x3 is int,
221 true))(Primitives.getMonth(this));
222 int get day => ((__x4) => DDC$RT.cast(__x4, dynamic, int, "CastGeneral",
223 """line 650, column 18 of dart:core/date_time.dart: """, __x4 is int,
224 true))(Primitives.getDay(this));
225 int get hour => ((__x5) => DDC$RT.cast(__x5, dynamic, int, "CastGeneral",
226 """line 658, column 19 of dart:core/date_time.dart: """, __x5 is int,
227 true))(Primitives.getHours(this));
228 int get minute => ((__x6) => DDC$RT.cast(__x6, dynamic, int, "CastGeneral",
229 """line 666, column 21 of dart:core/date_time.dart: """, __x6 is int,
230 true))(Primitives.getMinutes(this));
231 int get second => ((__x7) => DDC$RT.cast(__x7, dynamic, int, "CastGeneral",
232 """line 674, column 21 of dart:core/date_time.dart: """, __x7 is int,
233 true))(Primitives.getSeconds(this));
234 int get millisecond => ((__x8) => DDC$RT.cast(__x8, dynamic, int,
235 "CastGeneral", """line 682, column 26 of dart:core/date_time.dart: """,
236 __x8 is int, true))(Primitives.getMilliseconds(this));
237 int get weekday => ((__x9) => DDC$RT.cast(__x9, dynamic, int, "CastGeneral",
238 """line 695, column 22 of dart:core/date_time.dart: """, __x9 is int,
239 true))(Primitives.getWeekday(this));
240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698