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

Unified Diff: pkg/serialization/lib/src/serialization_rule.dart

Issue 14578008: Add a DateTimeRule to default serialization (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes from review Created 7 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 | « pkg/serialization/lib/serialization.dart ('k') | pkg/serialization/test/serialization_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/serialization/lib/src/serialization_rule.dart
diff --git a/pkg/serialization/lib/src/serialization_rule.dart b/pkg/serialization/lib/src/serialization_rule.dart
index 53c0f72990a54f60d76ce129fca8f2ac24c3800a..4ffe9663cea8eefeebf1e54546301035d1df844b 100644
--- a/pkg/serialization/lib/src/serialization_rule.dart
+++ b/pkg/serialization/lib/src/serialization_rule.dart
@@ -492,6 +492,18 @@ class SymbolRule extends CustomRule {
bool get hasVariableLengthEntries => false;
}
+/** A hard-coded rule for DateTime. */
+class DateTimeRule extends CustomRule {
+ bool appliesTo(instance, _) => instance is DateTime;
+ List getState(DateTime date) => [date.millisecondsSinceEpoch, date.isUtc];
+ create(List state) =>
+ new DateTime.fromMillisecondsSinceEpoch(state[0], isUtc: state[1]);
+ void setState(date, state) {}
+ // Let the system know we don't have to store a length for these.
+ int get dataLength => 2;
+ bool get hasVariableLengthEntries => false;
+}
+
/** Create a lazy list/map that will inflate its items on demand in [r]. */
_lazy(l, Reader r) {
if (l is List) return new _LazyList(l, r);
@@ -561,7 +573,7 @@ class _LazyList extends IterableBase implements List {
// These operations, and other inherited methods that iterate over the whole
// list will work, but may be expensive, and are probably
// best avoided.
- List get _inflated => _raw.map(_reader.inflateReference);
+ Iterable get _inflated => _raw.map(_reader.inflateReference);
Iterator get iterator => _inflated.iterator;
indexOf(x, [pos = 0]) => _inflated.toList().indexOf(x);
lastIndexOf(x, [pos]) => _inflated.toList().lastIndexOf(x);
« no previous file with comments | « pkg/serialization/lib/serialization.dart ('k') | pkg/serialization/test/serialization_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698