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); |