Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pranshugupta54 committed Oct 10, 2024
1 parent f210aab commit 59459a7
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.22.3"
}
15 changes: 10 additions & 5 deletions lib/services/database_mutation_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -99,8 +98,11 @@ class DataBaseMutationFunctions {
return await gqlAuthQuery(query, variables: variables);
}
} else if (result.data != null && result.isConcrete) {
traverseAndConvertDates(result.data as Map<String, dynamic>,
convertUTCToLocal, splitDateTimeLocal);
traverseAndConvertDates(
result.data ?? <String, dynamic>{},
convertUTCToLocal,
splitDateTimeLocal,
);
return result;
}
return noData;
Expand Down Expand Up @@ -219,8 +221,11 @@ class DataBaseMutationFunctions {
result.exception!,
);
} else if (result.data != null && result.isConcrete) {
traverseAndConvertDates(result.data as Map<String, dynamic>,
convertUTCToLocal, splitDateTimeLocal);
traverseAndConvertDates(
result.data ?? <String, dynamic>{},
convertUTCToLocal,
splitDateTimeLocal,
);
return result;
}
return noData;
Expand Down
17 changes: 8 additions & 9 deletions lib/utils/time_conversion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Map<String, String> 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),
};
}

Expand All @@ -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(
Expand All @@ -39,7 +39,7 @@ void traverseAndConvertDates(
final pairedFields =
dateTimeFields['pairedFields']?.cast<Map<String, String>>();
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,
Expand All @@ -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<String>()?.contains(key) ??
false) {
if (dateTimeFields['directFields']?.cast<String>().contains(key) ?? false) {
obj[key] = convertFn(value as String);
}

if (value is Map<String, dynamic>) {
traverseAndConvertDates(value, convertFn, splitFn);
} else if (value is List) {
for (var item in value) {
for (final item in value) {
if (item is Map<String, dynamic>) {
traverseAndConvertDates(item, convertFn, splitFn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ packages:
source: hosted
version: "0.4.1"
clock:
dependency: transitive
dependency: "direct main"
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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', () {
Expand Down Expand Up @@ -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', () {
Expand All @@ -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', () {
Expand All @@ -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', () {
Expand All @@ -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}$'),
);
});
});
});
Expand Down

0 comments on commit 59459a7

Please sign in to comment.