Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An instant in time, such as July 20, 1969, 8:18pm GMT. | 8 * An instant in time, such as July 20, 1969, 8:18pm GMT. |
| 9 * | 9 * |
| 10 * Create a DateTime object by using one of the constructors | 10 * Create a DateTime object by using one of the constructors |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 * time_opt ::= <empty> | (' ' | 'T') hour minutes_opt | 232 * time_opt ::= <empty> | (' ' | 'T') hour minutes_opt |
| 233 * minutes_opt ::= <empty> | ':' digit{2} seconds_opt | 233 * minutes_opt ::= <empty> | ':' digit{2} seconds_opt |
| 234 * seconds_opt ::= <empty> | ':' digit{2} millis_opt | 234 * seconds_opt ::= <empty> | ':' digit{2} millis_opt |
| 235 * millis_opt ::= <empty> | '.' digit{1,6} | 235 * millis_opt ::= <empty> | '.' digit{1,6} |
| 236 * timezone_opt ::= <empty> | space_opt timezone | 236 * timezone_opt ::= <empty> | space_opt timezone |
| 237 * space_opt :: ' ' | <empty> | 237 * space_opt :: ' ' | <empty> |
| 238 * timezone ::= 'z' | 'Z' | sign digit{2} timezonemins_opt | 238 * timezone ::= 'z' | 'Z' | sign digit{2} timezonemins_opt |
| 239 * timezonemins_opt ::= <empty> | colon_opt digit{2} | 239 * timezonemins_opt ::= <empty> | colon_opt digit{2} |
| 240 */ | 240 */ |
| 241 final RegExp re = new RegExp( | 241 final RegExp re = new RegExp( |
| 242 r'^([+-]?\d{4,5})-?(\d\d)-?(\d\d)' // The day part. | 242 r'^([+-]?\d{4,5})-?(\d\d)-?(\d\d)' // The day part. |
|
Lasse Reichstein Nielsen
2014/08/04 07:25:47
If the max year is 275760, this should probably be
srawlins
2014/08/04 19:58:30
Done.
| |
| 243 r'(?:[ T](\d\d)(?::?(\d\d)(?::?(\d\d)(.\d{1,6})?)?)?' // The time part | 243 r'(?:[ T](\d\d)(?::?(\d\d)(?::?(\d\d)(.\d{1,6})?)?)?' // The time part |
| 244 r'( ?[zZ]| ?([-+])(\d\d)(?::?(\d\d))?)?)?$'); // The timezone part | 244 r'( ?[zZ]| ?([-+])(\d\d)(?::?(\d\d))?)?)?$'); // The timezone part |
| 245 | 245 |
| 246 Match match = re.firstMatch(formattedString); | 246 Match match = re.firstMatch(formattedString); |
| 247 if (match != null) { | 247 if (match != null) { |
| 248 int parseIntOrZero(String matched) { | 248 int parseIntOrZero(String matched) { |
| 249 if (matched == null) return 0; | 249 if (matched == null) return 0; |
| 250 return int.parse(matched); | 250 return int.parse(matched); |
| 251 } | 251 } |
| 252 | 252 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 275 int sign = (match[9] == '-') ? -1 : 1; | 275 int sign = (match[9] == '-') ? -1 : 1; |
| 276 int hourDifference = int.parse(match[10]); | 276 int hourDifference = int.parse(match[10]); |
| 277 int minuteDifference = parseIntOrZero(match[11]); | 277 int minuteDifference = parseIntOrZero(match[11]); |
| 278 minuteDifference += 60 * hourDifference; | 278 minuteDifference += 60 * hourDifference; |
| 279 minute -= sign * minuteDifference; | 279 minute -= sign * minuteDifference; |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 int millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch( | 282 int millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch( |
| 283 years, month, day, hour, minute, second, millisecond, isUtc); | 283 years, month, day, hour, minute, second, millisecond, isUtc); |
| 284 if (millisecondsSinceEpoch == null) { | 284 if (millisecondsSinceEpoch == null) { |
| 285 throw new FormatException(formattedString); | 285 throw new FormatException('Out of range: $formattedString'); |
|
Lasse Reichstein Nielsen
2014/08/04 07:25:47
Use:
new FormattedException("Date out of range",
srawlins
2014/08/04 19:58:30
Done.
| |
| 286 } | 286 } |
| 287 if (addOneMillisecond) millisecondsSinceEpoch++; | 287 if (addOneMillisecond) millisecondsSinceEpoch++; |
| 288 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, | 288 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
| 289 isUtc: isUtc); | 289 isUtc: isUtc); |
| 290 } else { | 290 } else { |
| 291 throw new FormatException(formattedString); | 291 throw new FormatException('Could not parse: $formattedString'); |
|
Lasse Reichstein Nielsen
2014/08/04 07:25:47
throw new FormatException("Invalid DateTime format
srawlins
2014/08/04 19:58:30
Done.
| |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 static const int _MAX_MILLISECONDS_SINCE_EPOCH = 8640000000000000; | 295 static const int _MAX_MILLISECONDS_SINCE_EPOCH = 8640000000000000; |
| 296 | 296 |
| 297 /** | 297 /** |
| 298 * Constructs a new [DateTime] instance | 298 * Constructs a new [DateTime] instance |
| 299 * with the given [millisecondsSinceEpoch]. | 299 * with the given [millisecondsSinceEpoch]. |
| 300 * | 300 * |
| 301 * If [isUtc] is false then the date is in the local time zone. | 301 * If [isUtc] is false then the date is in the local time zone. |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 * In accordance with ISO 8601 | 622 * In accordance with ISO 8601 |
| 623 * a week starts with Monday, which has the value 1. | 623 * a week starts with Monday, which has the value 1. |
| 624 * | 624 * |
| 625 * DateTime moonLanding = DateTime.parse("1969-07-20 20:18:00"); | 625 * DateTime moonLanding = DateTime.parse("1969-07-20 20:18:00"); |
| 626 * assert(moonLanding.weekday == 7); | 626 * assert(moonLanding.weekday == 7); |
| 627 * assert(moonLanding.weekday == DateTime.SUNDAY); | 627 * assert(moonLanding.weekday == DateTime.SUNDAY); |
| 628 * | 628 * |
| 629 */ | 629 */ |
| 630 external int get weekday; | 630 external int get weekday; |
| 631 } | 631 } |
| OLD | NEW |