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

Unified Diff: lib/compiler/implementation/lib/mockimpl.dart

Issue 10391111: Support up to 6 digits after the decimal point in Date.fromString. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | « frog/lib/date_implementation.dart ('k') | runtime/lib/date.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/lib/mockimpl.dart
diff --git a/lib/compiler/implementation/lib/mockimpl.dart b/lib/compiler/implementation/lib/mockimpl.dart
index d6d8f5dc353dcc23da8a134c4f1f59022f97c6de..da80c14aa807b53ca08a0179fde9989a795b34bc 100644
--- a/lib/compiler/implementation/lib/mockimpl.dart
+++ b/lib/compiler/implementation/lib/mockimpl.dart
@@ -229,7 +229,7 @@ class DateImplementation implements Date {
// - "-123450101 00:00:00 Z" // In the year -12345.
final RegExp re = const RegExp(
@'^([+-]?\d?\d\d\d\d)-?(\d\d)-?(\d\d)' // The day part.
- @'(?:[ T](\d\d)(?::?(\d\d)(?::?(\d\d)(?:.(\d{1,5}))?)?)? ?([zZ])?)?$');
+ @'(?:[ T](\d\d)(?::?(\d\d)(?::?(\d\d)(.\d{1,6})?)?)? ?([zZ])?)?$');
Match match = re.firstMatch(formattedString);
if (match !== null) {
int parseIntOrZero(String matched) {
@@ -238,6 +238,12 @@ class DateImplementation implements Date {
return Math.parseInt(matched);
}
+ double parseDoubleOrZero(String matched) {
+ // TODO(floitsch): we should not need to test against the empty string.
+ if (matched === null || matched == "") return 0.0;
+ return Math.parseDouble(matched);
+ }
+
int years = Math.parseInt(match[1]);
int month = Math.parseInt(match[2]);
int day = Math.parseInt(match[3]);
@@ -245,26 +251,10 @@ class DateImplementation implements Date {
int minutes = parseIntOrZero(match[5]);
int seconds = parseIntOrZero(match[6]);
bool addOneMillisecond = false;
- int milliseconds = parseIntOrZero(match[7]);
- if (milliseconds != 0) {
- if (match[7].length == 1) {
- milliseconds *= 100;
- } else if (match[7].length == 2) {
- milliseconds *= 10;
- } else if (match[7].length == 3) {
- // Do nothing.
- } else if (match[7].length == 4) {
- addOneMillisecond = ((milliseconds % 10) >= 5);
- milliseconds ~/= 10;
- } else {
- assert(match[7].length == 5);
- addOneMillisecond = ((milliseconds %100) >= 50);
- milliseconds ~/= 100;
- }
- if (addOneMillisecond && milliseconds < 999) {
- addOneMillisecond = false;
- milliseconds++;
- }
+ int milliseconds = (parseDoubleOrZero(match[7]) * 1000).round();
+ if (milliseconds == 1000) {
+ addOneMillisecond = true;
+ milliseconds = 999;
}
// TODO(floitsch): we should not need to test against the empty string.
bool isUtc = (match[8] !== null) && (match[8] != "");
« no previous file with comments | « frog/lib/date_implementation.dart ('k') | runtime/lib/date.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698