From cf0e88e9b0c4afb4537bdfb516e1c5c2f0e43a4c Mon Sep 17 00:00:00 2001 From: Hui Zhao <10602282+HuiSF@users.noreply.github.com> Date: Tue, 8 Feb 2022 10:59:48 -0800 Subject: [PATCH 1/2] fix(datastore): DataTime value comparison is inaccurate (#1326) * fix(datastore): DataTime value comparison is inaccurate * Update unit test snapshots * Improve code comment --- .../query_predicate_test/query_predicate_test.dart | 6 +++--- .../query_predicate/temporal_predicate.json | 2 +- .../save_api/request/instance_without_predicate.json | 2 +- .../lib/src/types/temporal/temporal_datetime.dart | 12 ++++++------ .../test/amplify_temporal_datetime_test.dart | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/amplify_datastore/example/integration_test/query_test/query_predicate_test/query_predicate_test.dart b/packages/amplify_datastore/example/integration_test/query_test/query_predicate_test/query_predicate_test.dart index 3bed29623c..c76244fdf3 100644 --- a/packages/amplify_datastore/example/integration_test/query_test/query_predicate_test/query_predicate_test.dart +++ b/packages/amplify_datastore/example/integration_test/query_test/query_predicate_test/query_predicate_test.dart @@ -23,6 +23,8 @@ import 'boolean_query_predicate_test.dart' as boolean_query_predicate_tests; import 'enum_query_predicate_test.dart' as enum_query_predicate_tests; import 'compound_query_predicate_test.dart' as compound_query_predicate_tests; import 'aws_date_query_predicate_test.dart' as aws_date_query_predicate_test; +import 'aws_date_time_query_predicate_test.dart' + as aws_date_time_query_predicate_test; import 'aws_time_query_predicate_test.dart' as aws_time_query_predicate_test; import 'aws_timestamp_query_predicate_test.dart' as aws_timestamp_query_predicate_tests; @@ -38,9 +40,7 @@ void main() async { enum_query_predicate_tests.main(); compound_query_predicate_tests.main(); aws_date_query_predicate_test.main(); - // TODO: enable AWSDateTime test suite when this issue gets resolved: - // https://github.com/aws-amplify/amplify-flutter/issues/1245 - // aws_date_time_query_predicate_test.main(); + aws_date_time_query_predicate_test.main(); aws_time_query_predicate_test.main(); aws_timestamp_query_predicate_tests.main(); }); diff --git a/packages/amplify_datastore/test/resources/query_predicate/temporal_predicate.json b/packages/amplify_datastore/test/resources/query_predicate/temporal_predicate.json index 3e0a9bdb4c..1ee75f54a3 100644 --- a/packages/amplify_datastore/test/resources/query_predicate/temporal_predicate.json +++ b/packages/amplify_datastore/test/resources/query_predicate/temporal_predicate.json @@ -3,7 +3,7 @@ "field": "created", "fieldOperator": { "operatorName": "equal", - "value": "2020-01-01T00:00:00Z" + "value": "2020-01-01T00:00:00.000000000Z" } } } diff --git a/packages/amplify_datastore/test/resources/save_api/request/instance_without_predicate.json b/packages/amplify_datastore/test/resources/save_api/request/instance_without_predicate.json index 4de85ef8b9..e82daf2816 100644 --- a/packages/amplify_datastore/test/resources/save_api/request/instance_without_predicate.json +++ b/packages/amplify_datastore/test/resources/save_api/request/instance_without_predicate.json @@ -4,7 +4,7 @@ "id": "9fc5fab4-37ff-4566-97e5-19c5d58a4c22", "title": "New Post being saved", "rating": 10, - "created": "2020-11-12T03:15:48+03:18", + "created": "2020-11-12T03:15:48.000000000+03:18", "likeCount": null, "blog": null, "comments": null, diff --git a/packages/amplify_datastore_plugin_interface/lib/src/types/temporal/temporal_datetime.dart b/packages/amplify_datastore_plugin_interface/lib/src/types/temporal/temporal_datetime.dart index c9bf76b168..1a4a6b6b03 100644 --- a/packages/amplify_datastore_plugin_interface/lib/src/types/temporal/temporal_datetime.dart +++ b/packages/amplify_datastore_plugin_interface/lib/src/types/temporal/temporal_datetime.dart @@ -60,7 +60,7 @@ class TemporalDateTime implements Comparable { dateTime.microsecond); if (offset.inDays > 0) { - throw new Exception("Cannot have an offset in days (hh:mm:ss)"); + throw Exception("Cannot have an offset in days (hh:mm:ss)"); } _offset = offset; @@ -75,7 +75,7 @@ class TemporalDateTime implements Comparable { /// +hh:mm /// +hh:mm:ss TemporalDateTime.fromString(String iso8601String) { - RegExp regExp = new RegExp( + RegExp regExp = RegExp( r'^([0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9](:[0-5][0-9](\.([0-9]{1,9}))?)?)((z|Z)|((\+|-)[0-2][0-9]:[0-5][0-9](:[0-5][0-9])?))', caseSensitive: false, multiLine: false); @@ -90,7 +90,7 @@ class TemporalDateTime implements Comparable { } if (regexString != iso8601String) { - throw new Exception("invalid string input"); + throw Exception("invalid string input"); } // Extract Time @@ -141,9 +141,9 @@ class TemporalDateTime implements Comparable { buffer.write(isoString.substring(0, isoString.length - 4)); int totalMicroseconds = _nanoseconds + Temporal.getNanoseconds(_dateTime); - if (totalMicroseconds > 0) { - buffer.write("." + totalMicroseconds.toString().padLeft(9, "0")); - } + // ensure DateTime strings stored in SQLite to be in the same format + // and string based DataTime comparison to be accurate + buffer.write("." + totalMicroseconds.toString().padLeft(9, "0")); if (_offset != null) { if (_offset!.inSeconds == 0) { diff --git a/packages/amplify_datastore_plugin_interface/test/amplify_temporal_datetime_test.dart b/packages/amplify_datastore_plugin_interface/test/amplify_temporal_datetime_test.dart index f7ab7b0f1f..725802fbfa 100644 --- a/packages/amplify_datastore_plugin_interface/test/amplify_temporal_datetime_test.dart +++ b/packages/amplify_datastore_plugin_interface/test/amplify_temporal_datetime_test.dart @@ -46,7 +46,7 @@ void main() { expect(time.getOffset(), Duration()); expect(time.getDateTimeInUtc(), DateTime.utc(1995, 05, 03, 03, 30)); - expect(time.format(), "1995-05-03T03:30:00Z"); + expect(time.format(), "1995-05-03T03:30:00.000000000Z"); }); test('AWSDateTime from string YYYY-MM-DDThh:mm:ssZ success', () async { @@ -54,7 +54,7 @@ void main() { expect(time.getOffset(), Duration()); expect(time.getDateTimeInUtc(), DateTime.utc(1995, 05, 03, 03, 30, 25)); - expect(time.format(), "1995-05-03T03:30:25Z"); + expect(time.format(), "1995-05-03T03:30:25.000000000Z"); }); test('AWSDateTime from string YYYY-MM-DDThh:mm:ss.sssZ success', () async { @@ -74,7 +74,7 @@ void main() { expect(time.getOffset(), duration); expect(time.getDateTimeInUtc(), DateTime.utc(1995, 05, 03, 03, 30)); - expect(time.format(), "1995-05-03T03:30:00+03:25"); + expect(time.format(), "1995-05-03T03:30:00.000000000+03:25"); }); test('AWSDateTime from string YYYY-MM-DDThh:mm-hh:mm success', () async { @@ -84,7 +84,7 @@ void main() { expect(time.getOffset(), duration); expect(time.getDateTimeInUtc(), DateTime.utc(1995, 05, 03, 03, 30)); - expect(time.format(), "1995-05-03T03:30:00-03:25"); + expect(time.format(), "1995-05-03T03:30:00.000000000-03:25"); }); test('AWSDateTime from string YYYY-MM-DDThh:mm+hh:mm:ss success', () async { @@ -94,7 +94,7 @@ void main() { expect(time.getOffset(), duration); expect(time.getDateTimeInUtc(), DateTime.utc(1995, 05, 03, 03, 30)); - expect(time.format(), "1995-05-03T03:30:00+03:25:55"); + expect(time.format(), "1995-05-03T03:30:00.000000000+03:25:55"); }); test('AWSDateTime from string YYYY-MM-DDThh:mm:ss+hh:mm:ss success', @@ -105,7 +105,7 @@ void main() { expect(time.getOffset(), duration); expect(time.getDateTimeInUtc(), DateTime.utc(1995, 05, 03, 03, 30, 25)); - expect(time.format(), "1995-05-03T03:30:25+03:25:55"); + expect(time.format(), "1995-05-03T03:30:25.000000000+03:25:55"); }); test('AWSDateTime from string YYYY-MM-DDThh:mm:ss.sss+hh:mm:ss success', From b5a1c3a5b33f39adee4c1e387247f03be3e6fec4 Mon Sep 17 00:00:00 2001 From: Jordan Nelson Date: Thu, 10 Feb 2022 16:10:28 -0500 Subject: [PATCH 2/2] chore: remove comments from schema file (#1347) --- .../amplify_datastore/example/tool/schema.graphql | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/amplify_datastore/example/tool/schema.graphql b/packages/amplify_datastore/example/tool/schema.graphql index b38189af6b..32dd0aa29d 100644 --- a/packages/amplify_datastore/example/tool/schema.graphql +++ b/packages/amplify_datastore/example/tool/schema.graphql @@ -1,8 +1,6 @@ -# This "input" configures a global authorization rule to enable public access to -# all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql/authorization-rules input AMPLIFY { globalAuthRule: AuthRule = { allow: public } -} # FOR TESTING ONLY! +} type Blog @model { id: ID! name: String! @@ -33,7 +31,6 @@ type Tag @model { posts: [Post] @manyToMany(relationName: "PostTags") } -# scalar types, enum and CustomType type ModelWithAppsyncScalarTypes @model { id: ID! stringValue: String @@ -112,9 +109,6 @@ type SimpleCustomType { foo: String! } -# Model relationships - -# models with has one relationship type HasOneParent @model { id: ID! name: String @@ -128,7 +122,6 @@ type HasOneChild @model { name: String } -# models with has many relationship type HasManyParent @model { id: ID! name: String @@ -175,7 +168,6 @@ type HasManyChildBiDirectionalExplicit @model { @belongsTo(fields: ["hasManyParentId"]) } -# models with belongs to relationship type BelongsToParent @model { id: ID! name: String @@ -196,7 +188,6 @@ type BelongsToChildExplicit @model { belongsToParent: BelongsToParent @belongsTo(fields: ["belongsToParentID"]) } -# models with multiple relationships type MultiRelatedMeeting @model { id: ID! @primaryKey title: String!