| Index: frog/leg/lib/mockimpl.dart
|
| diff --git a/frog/leg/lib/mockimpl.dart b/frog/leg/lib/mockimpl.dart
|
| index 0c318dfda5e5ad6de3caf80c345141b69ffd8cdb..9f6dbbcc086597a3c8126646068709fd9337b22f 100644
|
| --- a/frog/leg/lib/mockimpl.dart
|
| +++ b/frog/leg/lib/mockimpl.dart
|
| @@ -235,10 +235,40 @@ class DateImplementation implements Date {
|
| _asJs();
|
| }
|
|
|
| - DateImplementation.fromString(String formattedString)
|
| - : timeZone = new TimeZone.local(),
|
| - value = Primitives.valueFromDateString(formattedString) {
|
| - _asJs();
|
| + factory DateImplementation.fromString(String formattedString) {
|
| + // JavaScript's parse function is not specified and there are differences
|
| + // between the different implementations. Make sure we can at least read in
|
| + // Dart's output: try to read in (a subset of) ISO 8601 first. If that fails
|
| + // fall back to JavaScript's implementation.
|
| + 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);
|
|
|