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

Unified Diff: runtime/lib/date.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 | « lib/compiler/implementation/lib/mockimpl.dart ('k') | tests/corelib/date_time4_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/date.dart
diff --git a/runtime/lib/date.dart b/runtime/lib/date.dart
index 6b89dfd70d5d329a8324cc258ea7e6c3e03a0abd..d4839258df5f4cf119fc5d33b9e324dbd55c255c 100644
--- a/runtime/lib/date.dart
+++ b/runtime/lib/date.dart
@@ -62,7 +62,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) {
@@ -71,6 +71,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]);
@@ -78,26 +84,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 | « lib/compiler/implementation/lib/mockimpl.dart ('k') | tests/corelib/date_time4_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698