From 59459a79f67b13518aed12e554682ce27609d5a4 Mon Sep 17 00:00:00 2001 From: Pranshu Date: Fri, 11 Oct 2024 00:26:33 +0530 Subject: [PATCH] lint --- .fvmrc | 3 + lib/services/database_mutation_functions.dart | 15 +++-- lib/utils/time_conversion.dart | 17 +++-- .../create_event_view_model.dart | 7 +-- pubspec.lock | 2 +- pubspec.yaml | 1 + .../events/time_conversion_test.dart | 63 ++++++++++++------- 7 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 .fvmrc diff --git a/.fvmrc b/.fvmrc new file mode 100644 index 000000000..cf7449069 --- /dev/null +++ b/.fvmrc @@ -0,0 +1,3 @@ +{ + "flutter": "3.22.3" +} \ No newline at end of file diff --git a/lib/services/database_mutation_functions.dart b/lib/services/database_mutation_functions.dart index 725fda91c..136f87005 100644 --- a/lib/services/database_mutation_functions.dart +++ b/lib/services/database_mutation_functions.dart @@ -6,7 +6,6 @@ import 'package:talawa/locator.dart'; import 'package:talawa/models/organization/org_info.dart'; import 'package:talawa/utils/post_queries.dart'; import 'package:talawa/utils/queries.dart'; -import 'package:talawa/view_model/connectivity_view_model.dart'; import 'package:talawa/utils/time_conversion.dart'; /// DataBaseMutationFunctions class provides different services that are under the context of graphQL mutations and queries. @@ -99,8 +98,11 @@ class DataBaseMutationFunctions { return await gqlAuthQuery(query, variables: variables); } } else if (result.data != null && result.isConcrete) { - traverseAndConvertDates(result.data as Map, - convertUTCToLocal, splitDateTimeLocal); + traverseAndConvertDates( + result.data ?? {}, + convertUTCToLocal, + splitDateTimeLocal, + ); return result; } return noData; @@ -219,8 +221,11 @@ class DataBaseMutationFunctions { result.exception!, ); } else if (result.data != null && result.isConcrete) { - traverseAndConvertDates(result.data as Map, - convertUTCToLocal, splitDateTimeLocal); + traverseAndConvertDates( + result.data ?? {}, + convertUTCToLocal, + splitDateTimeLocal, + ); return result; } return noData; diff --git a/lib/utils/time_conversion.dart b/lib/utils/time_conversion.dart index 01c1e9f8e..113a271e4 100644 --- a/lib/utils/time_conversion.dart +++ b/lib/utils/time_conversion.dart @@ -8,7 +8,7 @@ Map splitDateTimeUTC(String dateTimeStr) { final DateTime dateTime = DateTime.parse(dateTimeStr); return { 'date': DateFormat('yyyy-MM-dd').format(dateTime), - 'time': DateFormat('HH:mm:ss.SSS\'Z\'').format(dateTime), + 'time': DateFormat("HH:mm:ss.SSS'Z'").format(dateTime), }; } @@ -27,7 +27,7 @@ String convertUTCToLocal(String utcTime) { String convertLocalToUTC(String localTime) { final DateTime dateTime = DateTime.parse(localTime).toUtc(); - return DateFormat('yyyy-MM-ddTHH:mm:ss.SSS\'Z\'').format(dateTime); + return DateFormat("yyyy-MM-ddTHH:mm:ss.SSS'Z'").format(dateTime); } void traverseAndConvertDates( @@ -39,7 +39,7 @@ void traverseAndConvertDates( final pairedFields = dateTimeFields['pairedFields']?.cast>(); if (pairedFields != null) { - for (var field in pairedFields) { + for (final field in pairedFields) { if (key == field['dateField'] && obj.containsKey(field['timeField'])) { final combinedDateTime = combineDateTime( obj[field['dateField']] as String, @@ -48,23 +48,22 @@ void traverseAndConvertDates( final convertedDateTime = convertFn(combinedDateTime); - final splitDateTime = splitFn(convertedDateTime ?? ''); + final splitDateTime = splitFn(convertedDateTime); - obj[field['dateField'] as String] = splitDateTime['date'] ?? ''; - obj[field['timeField'] as String] = splitDateTime['time'] ?? ''; + obj[field['dateField'] ?? ''] = splitDateTime['date'] ?? ''; + obj[field['timeField'] ?? ''] = splitDateTime['time'] ?? ''; } } } - if (dateTimeFields['directFields']?.cast()?.contains(key) ?? - false) { + if (dateTimeFields['directFields']?.cast().contains(key) ?? false) { obj[key] = convertFn(value as String); } if (value is Map) { traverseAndConvertDates(value, convertFn, splitFn); } else if (value is List) { - for (var item in value) { + for (final item in value) { if (item is Map) { traverseAndConvertDates(item, convertFn, splitFn); } diff --git a/lib/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart b/lib/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart index 6ab5c673d..6d7f44371 100644 --- a/lib/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart +++ b/lib/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart @@ -225,11 +225,10 @@ class CreateEventViewModel extends BaseModel { 'organizationId': _currentOrg.id, 'startDate': DateFormat('yyyy-MM-dd').format(eventStartDate), 'endDate': DateFormat('yyyy-MM-dd').format(eventEndDate), - 'startTime': isAllDay - ? null - : '${DateFormat('HH:mm:ss').format(startTime)}', + 'startTime': + isAllDay ? null : DateFormat('HH:mm:ss').format(startTime), 'endTime': - isAllDay ? null : '${DateFormat('HH:mm:ss').format(endTime)}', + isAllDay ? null : DateFormat('HH:mm:ss').format(endTime), }, if (isRecurring) 'recurrenceRuleData': { diff --git a/pubspec.lock b/pubspec.lock index 978d19581..d117a4486 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -178,7 +178,7 @@ packages: source: hosted version: "0.4.1" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/pubspec.yaml b/pubspec.yaml index 1afc201d1..10dae5c4e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,6 +21,7 @@ dependencies: auto_size_text: ^3.0.0 cached_network_image: ^3.4.1 + clock: ^1.1.1 connectivity_plus: ^5.0.2 contained_tab_bar_view: ^0.8.0 diff --git a/test/widget_tests/after_auth_screens/events/time_conversion_test.dart b/test/widget_tests/after_auth_screens/events/time_conversion_test.dart index 5ac79174b..7b5eb3ec8 100644 --- a/test/widget_tests/after_auth_screens/events/time_conversion_test.dart +++ b/test/widget_tests/after_auth_screens/events/time_conversion_test.dart @@ -1,8 +1,8 @@ +import 'package:clock/clock.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; import 'package:talawa/utils/time_conversion.dart'; + import '../../../helpers/test_helpers.dart'; -import 'package:clock/clock.dart'; void main() { group('Time Conversion Utils', () { @@ -31,19 +31,23 @@ void main() { }); test('convertUTCToLocal converts UTC to local time', () { - final utcTime = '2023-05-01T14:30:00.000Z'; + const utcTime = '2023-05-01T14:30:00.000Z'; final localTime = convertUTCToLocal(utcTime); expect(localTime, isNot(equals(utcTime))); expect( - localTime, matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$')); + localTime, + matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$'), + ); }); test('convertLocalToUTC converts local to UTC time', () { - final localTime = '2023-05-01T14:30:00.000'; + const localTime = '2023-05-01T14:30:00.000'; final utcTime = convertLocalToUTC(localTime); expect(utcTime, isNot(equals(localTime))); expect( - utcTime, matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$')); + utcTime, + matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$'), + ); }); group('traverseAndConvertDates', () { @@ -54,8 +58,10 @@ void main() { }; traverseAndConvertDates(testObj, convertUTCToLocal, splitDateTimeLocal); expect(testObj['createdAt'], isNot(equals('2023-05-01T14:30:00.000Z'))); - expect(testObj['createdAt'], - matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$')); + expect( + testObj['createdAt'], + matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$'), + ); }); test('converts paired fields', () { @@ -77,10 +83,14 @@ void main() { }, }; traverseAndConvertDates(testObj, convertUTCToLocal, splitDateTimeLocal); - expect(testObj['user']?['createdAt'], - isNot(equals('2023-05-01T14:30:00.000Z'))); - expect(testObj['user']?['createdAt'], - matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$')); + expect( + testObj['user']?['createdAt'], + isNot(equals('2023-05-01T14:30:00.000Z')), + ); + expect( + testObj['user']?['createdAt'], + matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$'), + ); }); test('converts objects in lists', () { @@ -92,15 +102,26 @@ void main() { ], }; traverseAndConvertDates( - testObj, convertUTCToLocal, splitDateTimeLocal); - expect(testObj['items']?[0]['createdAt'], - isNot(equals('2023-05-01T14:30:00.000Z'))); - expect(testObj['items']?[0]['createdAt'], - matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$')); - expect(testObj['items']?[1]['createdAt'], - isNot(equals('2023-05-02T15:45:00.000Z'))); - expect(testObj['items']?[1]['createdAt'], - matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$')); + testObj, + convertUTCToLocal, + splitDateTimeLocal, + ); + expect( + testObj['items']?[0]['createdAt'], + isNot(equals('2023-05-01T14:30:00.000Z')), + ); + expect( + testObj['items']?[0]['createdAt'], + matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$'), + ); + expect( + testObj['items']?[1]['createdAt'], + isNot(equals('2023-05-02T15:45:00.000Z')), + ); + expect( + testObj['items']?[1]['createdAt'], + matches(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$'), + ); }); }); });