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

Unified Diff: frog/leg/lib/mockimpl.dart

Issue 9466048: Implement (subset of) ISO 8601 for date-reading. Fix other bugs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add assert. Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | frog/lib/date_implementation.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/lib/mockimpl.dart
diff --git a/frog/leg/lib/mockimpl.dart b/frog/leg/lib/mockimpl.dart
index 0c318dfda5e5ad6de3caf80c345141b69ffd8cdb..63662bb9ae6a04ffae17f365455f340a14e3e381 100644
--- a/frog/leg/lib/mockimpl.dart
+++ b/frog/leg/lib/mockimpl.dart
@@ -235,10 +235,38 @@ class DateImplementation implements Date {
_asJs();
}
- DateImplementation.fromString(String formattedString)
- : timeZone = new TimeZone.local(),
- value = Primitives.valueFromDateString(formattedString) {
- _asJs();
+ factory DateImplementation.fromString(String formattedString) {
+ // Always try to read in (a subset of) ISO 8601 first. If that fails fall
+ // back to JavaScript's implementation.
ngeoffray 2012/02/27 17:05:41 Please explain why you're doing this.
floitsch 2012/02/27 18:05:27 Done.
+ final RegExp re =
+ const RegExp(@'^([+-]?\d?\d\d\d\d)-?(\d\d)-?(\d\d) (\d\d):(\d\d):(\d\d)(?:.(\d{1,3}))? ?([zZ]?)$');
+ Match match = re.firstMatch(formattedString);
+ if (match !== null) {
+ int years = Math.parseInt(match[1]);
+ int month = Math.parseInt(match[2]);
+ int day = Math.parseInt(match[3]);
+ int hours = Math.parseInt(match[4]);
+ int minutes = Math.parseInt(match[5]);
+ int seconds = Math.parseInt(match[6]);
+ int milliseconds = 0;
+ if (match[7] !== null) {
+ milliseconds = Math.parseInt(match[7]);
+ if (match[7].length == 1) {
+ milliseconds *= 100;
+ } else if (match[7].length == 2) {
+ milliseconds *= 10;
+ } else {
+ assert(match[7].length == 3);
+ }
+ }
+ bool isUtc = match[8] !== null;
+ TimeZone timezone = isUtc ? const TimeZone.utc() : new TimeZone.local();
+ return new DateImplementation.withTimeZone(
+ years, month, day, hours, minutes, seconds, milliseconds, timezone);
+ } else {
+ return new DateImplementation.fromEpoch(formattedString,
+ new TimeZone.local());
+ }
}
const DateImplementation.fromEpoch(this.value, this.timeZone);
« no previous file with comments | « no previous file | frog/lib/date_implementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698