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

Side by Side Diff: pkg/intl/lib/date_format_helpers.dart

Issue 10916015: Parsing dates with format that's just month or day will fail on certain days (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | pkg/intl/test/date_time_format_test.dart » ('j') | 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 * A class for holding onto the data for a date so that it can be built 6 * A class for holding onto the data for a date so that it can be built
7 * up incrementally. 7 * up incrementally.
8 */ 8 */
9 class _DateBuilder { 9 class _DateBuilder {
10 int year = 0, 10 // Default the date values to the EPOCH so that there's a valid date
11 month = 0, 11 // in case the format doesn't set them.
12 day = 0, 12 int year = 1970,
13 month = 1,
14 day = 1,
13 hour = 0, 15 hour = 0,
14 minute = 0, 16 minute = 0,
15 second = 0, 17 second = 0,
16 fractionalSecond = 0; 18 fractionalSecond = 0;
17 bool pm = false; 19 bool pm = false;
18 bool utc = false; 20 bool utc = false;
19 21
20 // Functions that exist just to be closurized so we can pass them to a general 22 // Functions that exist just to be closurized so we can pass them to a general
21 // method. 23 // method.
22 void setYear(x) { year = x; } 24 void setYear(x) { year = x; }
23 void setMonth(x) { month = x; } 25 void setMonth(x) { month = x; }
24 void setDay(x) { day = x; } 26 void setDay(x) { day = x; }
25 void setHour(x) { hour = x; } 27 void setHour(x) { hour = x; }
26 void setMinute(x) { minute = x; } 28 void setMinute(x) { minute = x; }
27 void setSecond(x) { second = x; } 29 void setSecond(x) { second = x; }
28 void setFractionalSecond(x) { fractionalSecond = x; } 30 void setFractionalSecond(x) { fractionalSecond = x; }
29 31
30 /** 32 /**
31 * Return a date built using our values. If no date portion is set, 33 * Return a date built using our values. If no date portion is set,
32 * use today's date, as otherwise the constructor will fail. 34 * use the "Epoch" of January 1, 1970.
33 */ 35 */
34 Date asDate() { 36 Date asDate() {
Anton Muhin 2012/08/30 17:52:11 nit: you may prefer arrow syntax now.
35 if (year == 0 || month == 0 || day == 0) {
36 var today = new Date.now();
37 if (year == 0) year = today.year;
38 if (month == 0) month = today.month;
39 if (day == 0) day = today.day;
40 }
41
42 // TODO(alanknight): Validate the date, especially for things which 37 // TODO(alanknight): Validate the date, especially for things which
43 // can crash the VM, e.g. large month values. 38 // can crash the VM, e.g. large month values.
44 return new Date( 39 return new Date(
45 year, 40 year,
46 month, 41 month,
47 day, 42 day,
48 pm ? hour + 12 : hour, 43 pm ? hour + 12 : hour,
49 minute, 44 minute,
50 second, 45 second,
51 fractionalSecond, 46 fractionalSecond,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 * can see and then return the corresponding integer. Advance the stream. 121 * can see and then return the corresponding integer. Advance the stream.
127 */ 122 */
128 var digitMatcher = const RegExp(@'\d+'); 123 var digitMatcher = const RegExp(@'\d+');
129 int nextInteger() { 124 int nextInteger() {
130 var string = digitMatcher.stringMatch(rest()); 125 var string = digitMatcher.stringMatch(rest());
131 if (string == null || string.isEmpty()) return null; 126 if (string == null || string.isEmpty()) return null;
132 read(string.length); 127 read(string.length);
133 return parseInt(string); 128 return parseInt(string);
134 } 129 }
135 } 130 }
OLDNEW
« no previous file with comments | « no previous file | pkg/intl/test/date_time_format_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698