diff --git a/lib/note.dart b/lib/note.dart index 478f8728..9a72e4fc 100644 --- a/lib/note.dart +++ b/lib/note.dart @@ -28,7 +28,7 @@ class Note implements Comparable { if (json.containsKey("created")) { var createdStr = json['created'].toString(); try { - created = DateTime.parse(json['created']); + created = DateTime.parse(json['created']).toLocal(); } catch (ex) {} if (created == null) { @@ -37,7 +37,7 @@ class Note implements Comparable { if (regex.hasMatch(createdStr)) { // FIXME: Handle the timezone! createdStr = createdStr.substring(0, 19); - created = DateTime.parse(json['created']); + created = DateTime.parse(createdStr); } } @@ -89,7 +89,12 @@ class Note implements Comparable { id == other.id && body == other.body && created == other.created && - extraProperties == other.extraProperties; + _equalMaps(extraProperties, other.extraProperties); + + static bool _equalMaps(Map a, Map b) { + if (a.length != b.length) return false; + return a.keys.every((key) => b.containsKey(key) && a[key] == b[key]); + } @override String toString() { diff --git a/test/serializers_test.dart b/test/serializers_test.dart index 28922554..8279463b 100644 --- a/test/serializers_test.dart +++ b/test/serializers_test.dart @@ -3,10 +3,15 @@ import 'package:journal/storage/serializers.dart'; import 'package:test/test.dart'; +DateTime nowWithoutMicro() { + var dt = DateTime.now(); + return DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second); +} + main() { group('Serializers', () { var note = - Note(id: "2", body: "This is the body", created: new DateTime.now()); + Note(id: "2", body: "This is the body", created: nowWithoutMicro()); test('JSON Serializer', () { var serializer = new JsonNoteSerializer();