diff --git a/app/lib/blackboard/blackboard_item.dart b/app/lib/blackboard/blackboard_item.dart index dc47e3fd5..2e7bffc7f 100644 --- a/app/lib/blackboard/blackboard_item.dart +++ b/app/lib/blackboard/blackboard_item.dart @@ -6,6 +6,7 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore_helper/cloud_firestore_helper.dart'; @@ -64,7 +65,7 @@ class BlackboardItem { title: "", text: null, pictureURL: "", - createdOn: DateTime.now(), + createdOn: clock.now(), attachments: [], sendNotification: true, forUsers: {}, diff --git a/app/lib/changelog/change_database_model.dart b/app/lib/changelog/change_database_model.dart index 02989a534..0dca75e9f 100644 --- a/app/lib/changelog/change_database_model.dart +++ b/app/lib/changelog/change_database_model.dart @@ -6,9 +6,10 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:sharezone/changelog/change.dart'; import 'package:cloud_firestore_helper/cloud_firestore_helper.dart'; +import 'package:sharezone/changelog/change.dart'; class ChangeDatabaseModel { final String id; @@ -32,7 +33,7 @@ class ChangeDatabaseModel { return ChangeDatabaseModel._( id: "", version: "", - releaseDate: DateTime.now(), + releaseDate: clock.now(), newFeatures: [], improvements: [], fixes: [], diff --git a/app/lib/comments/comment.dart b/app/lib/comments/comment.dart index 631f2d6f4..b8d0e53c5 100644 --- a/app/lib/comments/comment.dart +++ b/app/lib/comments/comment.dart @@ -6,6 +6,8 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; + import 'misc.dart'; class Comment { @@ -66,7 +68,7 @@ class CommentAge extends Duration { int get inApproximateYears => (inDays / approximateDaysPerMonth).round(); - DateTime get writtenOnDateTime => DateTime.now().subtract(this); + DateTime get writtenOnDateTime => clock.now().subtract(this); } class CommentAuthor { diff --git a/app/lib/comments/comment_data_models.dart b/app/lib/comments/comment_data_models.dart index ec4e1ea54..50254763b 100644 --- a/app/lib/comments/comment_data_models.dart +++ b/app/lib/comments/comment_data_models.dart @@ -6,9 +6,10 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:sharezone/comments/comment.dart'; import 'package:cloud_firestore_helper/cloud_firestore_helper.dart'; +import 'package:sharezone/comments/comment.dart'; class CommentDataModel { final String? id; @@ -73,8 +74,7 @@ class CommentDataModel { author: author.toModel(), content: comment, ratings: _createRatings(), - age: CommentAge.fromDuration( - DateTime.now().difference(writtenOn!.toDate())), + age: CommentAge.fromDuration(clock.now().difference(writtenOn!.toDate())), id: id, ); } diff --git a/app/lib/dashboard/bloc/dashboard_bloc.dart b/app/lib/dashboard/bloc/dashboard_bloc.dart index 54e165a97..dd2043af2 100644 --- a/app/lib/dashboard/bloc/dashboard_bloc.dart +++ b/app/lib/dashboard/bloc/dashboard_bloc.dart @@ -9,6 +9,7 @@ import 'dart:async'; import 'package:bloc_base/bloc_base.dart'; +import 'package:clock/clock.dart'; import 'package:date/date.dart'; import 'package:design/design.dart'; import 'package:firebase_hausaufgabenheft_logik/firebase_hausaufgabenheft_logik.dart'; @@ -52,7 +53,7 @@ extension RepeatEveryExtension on Stream { class DashboardBloc extends BlocBase { final String _uid; final todayDateTimeWithoutTime = - DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day); + DateTime(clock.now().year, clock.now().month, clock.now().day); final _unreadBlackboardViewsSubject = BehaviorSubject>(); final _unreadBlackboardItemsEmptySubject = BehaviorSubject(); @@ -152,7 +153,7 @@ class DashboardBloc extends BlocBase { List _filterUrgentHomeworks( List allHomeworks, TypeOfUser typeOfUser) { - final now = DateTime.now(); + final now = clock.now(); final dayAfterTomorrow = DateTime(now.year, now.month, now.day + 2); // Was passiert, wenn der 30. Oktober ist und 2 Tage dazu gezählt werden? Springt es dann auf den 1. November um? // Antwort: Springt um auf den 1.November, gechekt, auf wenn der Code unschön ist, besser wäre dayAfterTomorrow = now.add(Duration(days:2)) @@ -286,7 +287,7 @@ extension on DateTime { bool get isDayAfterTomorrow => dayAfterTomorrow == withoutTime; static DateTime get today => - DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day); + DateTime(clock.now().year, clock.now().month, clock.now().day); static DateTime get tomorrow => DateTime(today.year, today.month, today.day + 1); static DateTime get dayAfterTomorrow => diff --git a/app/lib/dashboard/dashboard_page.dart b/app/lib/dashboard/dashboard_page.dart index 0f8b7e0f0..366f54976 100644 --- a/app/lib/dashboard/dashboard_page.dart +++ b/app/lib/dashboard/dashboard_page.dart @@ -10,6 +10,7 @@ import 'dart:developer'; import 'package:analytics/analytics.dart'; import 'package:bloc_provider/bloc_provider.dart'; +import 'package:clock/clock.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; diff --git a/app/lib/dashboard/models/homework_view.dart b/app/lib/dashboard/models/homework_view.dart index 6c058537f..2a6486b57 100644 --- a/app/lib/dashboard/models/homework_view.dart +++ b/app/lib/dashboard/models/homework_view.dart @@ -6,6 +6,7 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:firebase_hausaufgabenheft_logik/firebase_hausaufgabenheft_logik.dart'; import 'package:flutter/material.dart'; import 'package:group_domain_models/group_domain_models.dart'; @@ -39,7 +40,7 @@ class HomeworkView { } final todayDateTimeWithoutTime = - DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day); + DateTime(clock.now().year, clock.now().month, clock.now().day); if (dateTime.isBefore(todayDateTimeWithoutTime)) { return "Überfällig!"; } else if (dateTime.isAtSameMomentAs(todayDateTimeWithoutTime)) { @@ -62,8 +63,8 @@ class HomeworkView { final defaultColor = Colors.grey[400]!; if (!withUrgentColor) return defaultColor; - final dayAfterTomorrow = DateTime( - DateTime.now().year, DateTime.now().month, DateTime.now().day + 2); + final dayAfterTomorrow = + DateTime(clock.now().year, clock.now().month, clock.now().day + 2); return dateTime.isBefore(dayAfterTomorrow) ? Colors.redAccent : defaultColor; diff --git a/app/lib/dashboard/sections/holiday_countdown_section.dart b/app/lib/dashboard/sections/holiday_countdown_section.dart index dfe601eec..612e4dcab 100644 --- a/app/lib/dashboard/sections/holiday_countdown_section.dart +++ b/app/lib/dashboard/sections/holiday_countdown_section.dart @@ -123,8 +123,7 @@ class _HolidayText extends StatelessWidget { } // For each Holiday create a Widget and add to the list. for (var holiday in holidayList) { - int daysTillHolidayBeginn = - holiday!.start.difference(DateTime.now()).inDays; + int daysTillHolidayBeginn = holiday!.start.difference(clock.now()).inDays; String holidayTitle = capitalize(holiday.name); String emoji; @@ -139,7 +138,7 @@ class _HolidayText extends StatelessWidget { emoji = "🎉🎉🙌"; textWidget = Text("$holidayTitle: JETZT, WOOOOOOO! $emoji"); } else { - int daysTillHolidayEnd = holiday.end.difference(DateTime.now()).inDays; + int daysTillHolidayEnd = holiday.end.difference(clock.now()).inDays; if (daysTillHolidayEnd == 0) { textWidget = Text("$holidayTitle: Letzer Tag 😱"); } else { diff --git a/app/lib/dashboard/update_reminder/update_reminder_bloc.dart b/app/lib/dashboard/update_reminder/update_reminder_bloc.dart index 795a589c9..b29abf79b 100644 --- a/app/lib/dashboard/update_reminder/update_reminder_bloc.dart +++ b/app/lib/dashboard/update_reminder/update_reminder_bloc.dart @@ -7,6 +7,7 @@ // SPDX-License-Identifier: EUPL-1.2 import 'package:bloc_base/bloc_base.dart'; +import 'package:clock/clock.dart'; import 'package:crash_analytics/crash_analytics.dart'; import 'package:meta/meta.dart'; import 'package:sharezone/changelog/change.dart'; @@ -41,7 +42,7 @@ class UpdateReminderBloc extends BlocBase { getCurrentVersion: () => platformInformationRetriever.init().then( (_) => Version.parse(name: platformInformationRetriever.version)), updateGracePeriod: updateGracePeriod, - getCurrentDateTime: () => DateTime.now(), + getCurrentDateTime: () => clock.now(), crashAnalytics: crashAnalytics, ); } diff --git a/app/lib/feedback/src/cache/feedback_cache.dart b/app/lib/feedback/src/cache/feedback_cache.dart index 8b8e7cf9e..5bf026bf0 100644 --- a/app/lib/feedback/src/cache/feedback_cache.dart +++ b/app/lib/feedback/src/cache/feedback_cache.dart @@ -8,6 +8,7 @@ import 'dart:developer'; +import 'package:clock/clock.dart'; import 'package:key_value_store/key_value_store.dart'; import 'package:meta/meta.dart'; @@ -37,13 +38,13 @@ class FeedbackCache { } final durationPassedFromLastSubmit = - lastSubmit.difference(DateTime.now()).abs(); + lastSubmit.difference(clock.now()).abs(); if (durationPassedFromLastSubmit < feedbackCooldown) return true; return false; } Future setLastSubmit() async { - _cache.setString(lastSubmitCacheKey, DateTime.now().toIso8601String()); + _cache.setString(lastSubmitCacheKey, clock.now().toIso8601String()); } Future _getLastSubmitTime() async { diff --git a/app/lib/filesharing/logic/firebase_file_uploader/implementation/firebase_file_uploader_impl.dart b/app/lib/filesharing/logic/firebase_file_uploader/implementation/firebase_file_uploader_impl.dart index d0925a325..d04f6c265 100644 --- a/app/lib/filesharing/logic/firebase_file_uploader/implementation/firebase_file_uploader_impl.dart +++ b/app/lib/filesharing/logic/firebase_file_uploader/implementation/firebase_file_uploader_impl.dart @@ -6,6 +6,7 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:files_basics/files_models.dart'; import 'package:files_basics/local_file.dart'; @@ -45,7 +46,7 @@ class FirebaseFileUploaderImplementation { ChangeActivity( authorID: creatorID, authorName: creatorName, - changedOn: DateTime.now(), + changedOn: clock.now(), ) ], name: localFile.getName(), diff --git a/app/lib/holidays/holiday_bloc.dart b/app/lib/holidays/holiday_bloc.dart index 1a2ac2fd2..88e61305d 100644 --- a/app/lib/holidays/holiday_bloc.dart +++ b/app/lib/holidays/holiday_bloc.dart @@ -9,6 +9,7 @@ import 'dart:async'; import 'package:bloc_base/bloc_base.dart'; +import 'package:clock/clock.dart'; import 'package:holidays/holidays.dart'; import 'package:rxdart/subjects.dart'; import 'package:sharezone/util/api/user_api.dart'; @@ -34,7 +35,7 @@ class HolidayBloc extends BlocBase { {required this.holidayManager, required this.stateGateway, this.getCurrentTime}) { - getCurrentTime ??= () => DateTime.now(); + getCurrentTime ??= () => clock.now(); final holidaysStream = userState // StateEnum.notSelected would result into an UnsupportedStateException diff --git a/app/lib/homework/parent/homework_page.dart b/app/lib/homework/parent/homework_page.dart index eb97cf75b..fbf77efb9 100644 --- a/app/lib/homework/parent/homework_page.dart +++ b/app/lib/homework/parent/homework_page.dart @@ -11,20 +11,21 @@ import 'dart:developer'; import 'package:analytics/analytics.dart'; import 'package:bloc_provider/bloc_provider.dart'; +import 'package:clock/clock.dart'; import 'package:common_domain_models/common_domain_models.dart'; import 'package:firebase_hausaufgabenheft_logik/firebase_hausaufgabenheft_logik.dart'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; -import 'package:sharezone/main/application_bloc.dart'; -import 'package:sharezone/homework/parent/src/homework_page_bloc.dart'; +import 'package:sharezone/homework/homework_dialog/homework_dialog.dart'; import 'package:sharezone/homework/homework_page_new.dart'; +import 'package:sharezone/homework/parent/src/homework_page_bloc.dart'; +import 'package:sharezone/homework/shared/homework_archived.dart'; +import 'package:sharezone/homework/shared/homework_card.dart'; +import 'package:sharezone/main/application_bloc.dart'; import 'package:sharezone/navigation/logic/navigation_bloc.dart'; import 'package:sharezone/navigation/models/navigation_item.dart'; import 'package:sharezone/navigation/scaffold/app_bar_configuration.dart'; import 'package:sharezone/navigation/scaffold/sharezone_main_scaffold.dart'; -import 'package:sharezone/homework/shared/homework_archived.dart'; -import 'package:sharezone/homework/homework_dialog/homework_dialog.dart'; -import 'package:sharezone/homework/shared/homework_card.dart'; import 'package:sharezone_common/translations.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; import 'package:user/user.dart'; @@ -59,7 +60,7 @@ Future openHomeworkDialogAndShowConfirmationIfSuccessful( List getNotArchived(List homeworkList) { final List notArchivedHomeworks = []; for (var homework in homeworkList) { - final int dif = homework.todoUntil.difference(DateTime.now()).inDays; + final int dif = homework.todoUntil.difference(clock.now()).inDays; if (dif > -1) { notArchivedHomeworks.add(homework); } @@ -572,8 +573,8 @@ class _HomeworkListWithCards extends StatelessWidget { final List dayAfterTomorrowList = []; final List severalDaysList = []; - DateTime today = DateTime( - DateTime.now().year, DateTime.now().month, DateTime.now().day); + DateTime today = + DateTime(clock.now().year, clock.now().month, clock.now().day); for (var homework in homeworkList!) { DateTime homeworkDate = DateTime(homework.todoUntil.year, homework.todoUntil.month, homework.todoUntil.day); diff --git a/app/lib/homework/parent/src/homework_page_bloc.dart b/app/lib/homework/parent/src/homework_page_bloc.dart index c2ed3f4be..5ce3a3284 100644 --- a/app/lib/homework/parent/src/homework_page_bloc.dart +++ b/app/lib/homework/parent/src/homework_page_bloc.dart @@ -10,6 +10,7 @@ import 'dart:async'; import 'dart:developer'; import 'package:bloc_base/bloc_base.dart'; +import 'package:clock/clock.dart'; import 'package:firebase_hausaufgabenheft_logik/firebase_hausaufgabenheft_logik.dart'; import 'package:rxdart/subjects.dart'; import 'package:sharezone/util/api.dart'; @@ -116,8 +117,8 @@ class HomeworkPageBloc extends BlocBase { for (HomeworkDto homework in homeworkNotDone) { final DateTime homeworkDateTime = DateTime(homework.todoUntil.year, homework.todoUntil.month, homework.todoUntil.day); - final DateTime todayDateTime = DateTime( - DateTime.now().year, DateTime.now().month, DateTime.now().day); + final DateTime todayDateTime = + DateTime(clock.now().year, clock.now().month, clock.now().day); if (homeworkDateTime.isBefore(todayDateTime)) { api.homework.changeIsHomeworkDoneTo(homework.id, true); } diff --git a/app/lib/homework/shared/homework_archived.dart b/app/lib/homework/shared/homework_archived.dart index 76f86829a..cc2195ee4 100644 --- a/app/lib/homework/shared/homework_archived.dart +++ b/app/lib/homework/shared/homework_archived.dart @@ -9,12 +9,13 @@ import 'dart:developer'; import 'package:bloc_provider/bloc_provider.dart'; +import 'package:clock/clock.dart'; import 'package:firebase_hausaufgabenheft_logik/firebase_hausaufgabenheft_logik.dart'; import 'package:flutter/material.dart'; -import 'package:sharezone/main/application_bloc.dart'; -import 'package:sharezone/homework/parent/src/homework_page_bloc.dart'; import 'package:sharezone/homework/parent/homework_page.dart'; +import 'package:sharezone/homework/parent/src/homework_page_bloc.dart'; import 'package:sharezone/homework/shared/homework_card.dart'; +import 'package:sharezone/main/application_bloc.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; import 'package:user/user.dart'; @@ -63,8 +64,8 @@ class _HomeworkArchivedPageState extends State { return ShowCenteredError(error: snapshot.error.toString()); } - DateTime today = DateTime(DateTime.now().year, - DateTime.now().month, DateTime.now().day); + DateTime today = DateTime( + clock.now().year, clock.now().month, clock.now().day); List homeworkList = snapshot.data!.where((HomeworkDto homework) { DateTime todoUntil = DateTime(homework.todoUntil.year, diff --git a/app/lib/homework/shared/homework_card.dart b/app/lib/homework/shared/homework_card.dart index 79f377440..a58a63b8c 100644 --- a/app/lib/homework/shared/homework_card.dart +++ b/app/lib/homework/shared/homework_card.dart @@ -8,27 +8,28 @@ import 'package:analytics/analytics.dart'; import 'package:bloc_provider/bloc_provider.dart'; +import 'package:clock/clock.dart'; import 'package:common_domain_models/common_domain_models.dart'; import 'package:firebase_hausaufgabenheft_logik/firebase_hausaufgabenheft_logik.dart'; import 'package:flutter/material.dart'; import 'package:group_domain_models/group_domain_models.dart'; import 'package:intl/intl.dart'; -import 'package:sharezone/main/application_bloc.dart'; -import 'package:sharezone/homework/parent/src/homework_card_bloc.dart'; import 'package:sharezone/dashboard/models/homework_view.dart'; import 'package:sharezone/groups/src/pages/course/course_card.dart'; -import 'package:sharezone/homework/teacher/homework_done_by_users_list/homework_completion_user_list_page.dart'; import 'package:sharezone/homework/homework_details/homework_details.dart'; import 'package:sharezone/homework/homework_details/homework_details_view_factory.dart'; -import 'package:sharezone/homework/shared/homework_permissions.dart'; import 'package:sharezone/homework/parent/homework_page.dart'; +import 'package:sharezone/homework/parent/src/homework_card_bloc.dart'; +import 'package:sharezone/homework/shared/delete_homework.dart'; +import 'package:sharezone/homework/shared/homework_permissions.dart'; +import 'package:sharezone/homework/teacher/homework_done_by_users_list/homework_completion_user_list_page.dart'; +import 'package:sharezone/main/application_bloc.dart'; import 'package:sharezone/report/page/report_page.dart'; import 'package:sharezone/report/report_icon.dart'; import 'package:sharezone/report/report_item.dart'; import 'package:sharezone/submissions/homework_list_submissions_page.dart'; import 'package:sharezone/util/api/connections_gateway.dart'; import 'package:sharezone/util/navigation_service.dart'; -import 'package:sharezone/homework/shared/delete_homework.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; import 'package:user/user.dart'; @@ -52,8 +53,8 @@ class HomeworkCard extends StatelessWidget { final bloc = HomeworkCardBloc(api, homework!); final analytics = BlocProvider.of(context).analytics; - DateTime tomorrowWithoutTime = DateTime( - DateTime.now().year, DateTime.now().month, DateTime.now().day + 1); + DateTime tomorrowWithoutTime = + DateTime(clock.now().year, clock.now().month, clock.now().day + 1); DateTime todoUntilWithoutTime = DateTime(homework!.todoUntil.year, homework!.todoUntil.month, homework!.todoUntil.day); diff --git a/app/lib/main/sharezone_bloc_providers.dart b/app/lib/main/sharezone_bloc_providers.dart index aa2813915..e933f1d87 100644 --- a/app/lib/main/sharezone_bloc_providers.dart +++ b/app/lib/main/sharezone_bloc_providers.dart @@ -27,22 +27,21 @@ import 'package:flutter/material.dart'; import 'package:hausaufgabenheft_logik/hausaufgabenheft_logik_lehrer.dart'; import 'package:hausaufgabenheft_logik/hausaufgabenheft_logik_setup.dart'; import 'package:holidays/holidays.dart' hide State; +import 'package:http/http.dart' as http; import 'package:key_value_store/in_memory_key_value_store.dart'; import 'package:provider/provider.dart'; import 'package:sharezone/account/account_page_bloc_factory.dart'; +import 'package:sharezone/account/change_data_bloc.dart'; +import 'package:sharezone/account/type_of_user_bloc.dart'; import 'package:sharezone/activation_code/src/bloc/enter_activation_code_bloc_factory.dart'; import 'package:sharezone/blackboard/analytics/blackboard_analytics.dart'; import 'package:sharezone/blackboard/blocs/blackboard_page_bloc.dart'; -import 'package:sharezone/main/application_bloc.dart'; -import 'package:sharezone/account/type_of_user_bloc.dart'; -import 'package:sharezone/main/bloc_dependencies.dart'; -import 'package:sharezone/account/change_data_bloc.dart'; -import 'package:sharezone/notifications/notifications_bloc_factory.dart'; import 'package:sharezone/calendrical_events/analytics/calendrical_events_page_analytics.dart'; import 'package:sharezone/calendrical_events/analytics/past_calendrical_events_page_analytics.dart'; import 'package:sharezone/calendrical_events/bloc/calendrical_events_page_bloc_factory.dart'; import 'package:sharezone/calendrical_events/bloc/calendrical_events_page_cache.dart'; import 'package:sharezone/calendrical_events/provider/past_calendrical_events_page_controller_factory.dart'; +import 'package:sharezone/changelog/changelog_gateway.dart'; import 'package:sharezone/comments/comment_view_factory.dart'; import 'package:sharezone/comments/comments_analytics.dart'; import 'package:sharezone/comments/comments_bloc_factory.dart'; @@ -65,8 +64,11 @@ import 'package:sharezone/groups/src/pages/course/create/src/analytics/course_cr import 'package:sharezone/groups/src/pages/course/create/src/bloc/course_create_bloc_factory.dart'; import 'package:sharezone/groups/src/pages/course/create/src/gateway/course_create_gateway.dart'; import 'package:sharezone/homework/analytics/homework_analytics.dart'; +import 'package:sharezone/homework/homework_details/homework_details_view_factory.dart'; import 'package:sharezone/homework/student/src/mark_overdue_homework_prompt.dart'; import 'package:sharezone/homework/teacher/homework_done_by_users_list/homework_completion_user_list_bloc_factory.dart'; +import 'package:sharezone/main/application_bloc.dart'; +import 'package:sharezone/main/bloc_dependencies.dart'; import 'package:sharezone/main/onboarding/onboarding_navigator.dart'; import 'package:sharezone/main/plugin_initializations.dart'; import 'package:sharezone/markdown/markdown_analytics.dart'; @@ -76,14 +78,11 @@ import 'package:sharezone/navigation/scaffold/portable/bottom_navigation_bar/nav import 'package:sharezone/navigation/scaffold/portable/bottom_navigation_bar/tutorial/bnb_tutorial_analytics.dart'; import 'package:sharezone/navigation/scaffold/portable/bottom_navigation_bar/tutorial/bnb_tutorial_bloc.dart'; import 'package:sharezone/navigation/scaffold/portable/bottom_navigation_bar/tutorial/bnb_tutorial_cache.dart'; +import 'package:sharezone/notifications/notifications_bloc_factory.dart'; import 'package:sharezone/onboarding/bloc/registration_bloc.dart'; import 'package:sharezone/onboarding/group_onboarding/analytics/group_onboarding_analytics.dart'; import 'package:sharezone/onboarding/group_onboarding/logic/group_onboarding_bloc.dart'; import 'package:sharezone/onboarding/group_onboarding/logic/signed_up_bloc.dart'; -import 'package:sharezone/homework/homework_details/homework_details_view_factory.dart'; -import 'package:sharezone/changelog/changelog_gateway.dart'; -import 'package:sharezone/settings/src/subpages/timetable/bloc/timetable_settings_bloc_factory.dart'; -import 'package:sharezone/settings/src/subpages/timetable/time_picker_settings_cache.dart'; import 'package:sharezone/report/report_factory.dart'; import 'package:sharezone/report/report_gateway.dart'; import 'package:sharezone/settings/src/bloc/user_settings_bloc.dart'; @@ -91,6 +90,8 @@ import 'package:sharezone/settings/src/bloc/user_tips_bloc.dart'; import 'package:sharezone/settings/src/subpages/imprint/analytics/imprint_analytics.dart'; import 'package:sharezone/settings/src/subpages/imprint/bloc/imprint_bloc_factory.dart'; import 'package:sharezone/settings/src/subpages/imprint/gateway/imprint_gateway.dart'; +import 'package:sharezone/settings/src/subpages/timetable/bloc/timetable_settings_bloc_factory.dart'; +import 'package:sharezone/settings/src/subpages/timetable/time_picker_settings_cache.dart'; import 'package:sharezone/sharezone_plus/page/sharezone_plus_page_controller.dart'; import 'package:sharezone/sharezone_plus/subscription_service/revenue_cat_sharezone_plus_service.dart'; import 'package:sharezone/sharezone_plus/subscription_service/subscription_flag.dart'; @@ -114,11 +115,10 @@ import 'package:sharezone/util/platform_information_manager/get_platform_informa import 'package:sharezone_common/references.dart'; import 'package:stripe_checkout_session/stripe_checkout_session.dart'; import 'package:user/user.dart'; -import 'package:http/http.dart' as http; +import '../holidays/holiday_bloc.dart'; import '../homework/parent/src/homework_page_bloc.dart' as old; import '../notifications/is_firebase_messaging_supported.dart'; -import '../holidays/holiday_bloc.dart'; final navigationBloc = NavigationBloc(); @@ -548,7 +548,7 @@ class _SharezoneBlocProvidersState extends State { holidayManager: HolidayService( HolidayApi( holidayApiClient, - getCurrentTime: () => DateTime.now(), + getCurrentTime: () => clock.now(), ), HolidayCache( FlutterKeyValueStore(widget.blocDependencies.sharedPreferences), diff --git a/app/lib/report/report_factory.dart b/app/lib/report/report_factory.dart index 5e862b406..835f782e2 100644 --- a/app/lib/report/report_factory.dart +++ b/app/lib/report/report_factory.dart @@ -7,6 +7,7 @@ // SPDX-License-Identifier: EUPL-1.2 import 'package:bloc_base/bloc_base.dart'; +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'report.dart'; @@ -26,7 +27,7 @@ class ReportFactory extends BlocBase { String description, ReportReason reason, ui.ReportItemReference item) { validatePath(item.path); return Report( - createdOn: DateTime.now(), + createdOn: clock.now(), creatorID: uid, description: description, reason: reason, diff --git a/app/lib/settings/src/subpages/timetable/timetable_settings_page.dart b/app/lib/settings/src/subpages/timetable/timetable_settings_page.dart index 4984636f1..59000d2e0 100644 --- a/app/lib/settings/src/subpages/timetable/timetable_settings_page.dart +++ b/app/lib/settings/src/subpages/timetable/timetable_settings_page.dart @@ -7,20 +7,21 @@ // SPDX-License-Identifier: EUPL-1.2 import 'package:bloc_provider/bloc_provider.dart'; +import 'package:clock/clock.dart'; import 'package:date/date.dart'; import 'package:date/weektype.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:numberpicker/numberpicker.dart'; +import 'package:platform_check/platform_check.dart'; +import 'package:sharezone/settings/src/bloc/user_settings_bloc.dart'; import 'package:sharezone/settings/src/subpages/timetable/bloc/timetable_settings_bloc.dart'; import 'package:sharezone/settings/src/subpages/timetable/bloc/timetable_settings_bloc_factory.dart'; import 'package:sharezone/settings/src/subpages/timetable/periods/periods_edit_page.dart'; -import 'package:sharezone/settings/src/bloc/user_settings_bloc.dart'; import 'package:sharezone/settings/src/subpages/timetable/weekdays/weekdays_edit_page.dart'; import 'package:sharezone/timetable/src/edit_time.dart'; import 'package:sharezone/timetable/src/edit_weektype.dart'; import 'package:sharezone/timetable/src/models/lesson_length/lesson_length.dart'; -import 'package:platform_check/platform_check.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; import 'package:time/time.dart'; import 'package:user/user.dart'; @@ -112,7 +113,7 @@ class _ABWeekField extends StatelessWidget { Padding( padding: const EdgeInsets.fromLTRB(16, 0, 16, 12), child: Text( - "Diese Woche ist Kalenderwoche ${getWeekNumber(DateTime.now()).toString()}. A-Wochen sind ${_getAWeekIsEvenOrOddName(userSettings.isAWeekEvenWeek)} Kalenderwochen und somit ist aktuell eine ${_getCurrentWeekTypeName(userSettings.isAWeekEvenWeek)}.", + "Diese Woche ist Kalenderwoche ${getWeekNumber(clock.now()).toString()}. A-Wochen sind ${_getAWeekIsEvenOrOddName(userSettings.isAWeekEvenWeek)} Kalenderwochen und somit ist aktuell eine ${_getCurrentWeekTypeName(userSettings.isAWeekEvenWeek)}.", textAlign: TextAlign.left, style: const TextStyle(fontSize: 12, color: Colors.grey), @@ -137,7 +138,7 @@ class _ABWeekField extends StatelessWidget { } WeekType _getCurrentWeekType(bool isAWeekEvenWeek) { - final isCurrentWeekEven = getWeekNumber(DateTime.now()).isEven; + final isCurrentWeekEven = getWeekNumber(clock.now()).isEven; if (isCurrentWeekEven) { return isAWeekEvenWeek ? WeekType.a : WeekType.b; } else { diff --git a/app/lib/submissions/homework_list_submissions_page.dart b/app/lib/submissions/homework_list_submissions_page.dart index 828efa15f..32ddf6a0f 100644 --- a/app/lib/submissions/homework_list_submissions_page.dart +++ b/app/lib/submissions/homework_list_submissions_page.dart @@ -8,6 +8,7 @@ import 'package:abgabe_client_lib/abgabe_client_lib.dart'; import 'package:bloc_provider/bloc_provider.dart'; +import 'package:clock/clock.dart'; import 'package:files_basics/files_models.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -136,14 +137,14 @@ class _LoadingPlaceholder extends StatelessWidget { abbreviation: 'A', username: 'Patrick Star', submittedFiles: [], - lastActionDateTime: DateTime.now(), + lastActionDateTime: clock.now(), wasEditedAfterwards: false, ), CreatedSubmissionView( abbreviation: 'S', username: 'Spongebob Schwammkopf', submittedFiles: [], - lastActionDateTime: DateTime.now(), + lastActionDateTime: clock.now(), wasEditedAfterwards: false, ), ], afterDeadlineSubmissions: [ @@ -151,7 +152,7 @@ class _LoadingPlaceholder extends StatelessWidget { abbreviation: 'B', username: 'Thaddäus Tentakel', submittedFiles: [], - lastActionDateTime: DateTime.now(), + lastActionDateTime: clock.now(), wasEditedAfterwards: false, ), ], missingSubmissions: [ diff --git a/app/lib/timetable/src/edit_date.dart b/app/lib/timetable/src/edit_date.dart index 25de58e95..c04c4f324 100644 --- a/app/lib/timetable/src/edit_date.dart +++ b/app/lib/timetable/src/edit_date.dart @@ -6,6 +6,7 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:date/date.dart'; import 'package:flutter/material.dart'; @@ -76,7 +77,7 @@ Future selectDate( }) async { return showDatePicker( context: context, - initialDate: initialDate?.toDateTime ?? DateTime.now(), + initialDate: initialDate?.toDateTime ?? clock.now(), firstDate: Date("2019-01-01").toDateTime, lastDate: Date("2029-12-31").toDateTime, ).then((newDateTime) { diff --git a/app/lib/util/api/homework_api.dart b/app/lib/util/api/homework_api.dart index fcdd260e7..b81fbb910 100644 --- a/app/lib/util/api/homework_api.dart +++ b/app/lib/util/api/homework_api.dart @@ -9,6 +9,7 @@ import 'dart:async'; import 'dart:developer'; +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:filesharing_logic/filesharing_logic_models.dart'; import 'package:firebase_hausaufgabenheft_logik/firebase_hausaufgabenheft_logik.dart'; @@ -54,7 +55,7 @@ class HomeworkGateway { Future _setUpStreams( FirebaseFirestore firestore, TypeOfUser typeOfUser) async { - final now = DateTime.now(); + final now = clock.now(); final startOfThisDay = DateTime(now.year, now.month, now.day); if (typeOfUser == TypeOfUser.student) { diff --git a/app/test/feedback/feedback_cache_test.dart b/app/test/feedback/feedback_cache_test.dart index b8886fb9e..3482f1b46 100644 --- a/app/test/feedback/feedback_cache_test.dart +++ b/app/test/feedback/feedback_cache_test.dart @@ -6,6 +6,7 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:key_value_store/in_memory_key_value_store.dart'; import 'package:sharezone/feedback/src/cache/feedback_cache.dart'; @@ -29,7 +30,7 @@ void main() { "Returns no cooldown if cached last send time is more than cooldown range", () async { const cooldownDuration = Duration(minutes: 2); - final lastFeedbackSend = DateTime.now().subtract(cooldownDuration + + final lastFeedbackSend = clock.now().subtract(cooldownDuration + const Duration(seconds: 10)); // So Feedback should get no cooldown dummyKeyValueStore.setString( @@ -44,7 +45,7 @@ void main() { "Returns cooldown if cached last send time is less than cooldown range", () async { const cooldownDuration = Duration(minutes: 2); - final lastFeedbackSend = DateTime.now().subtract(cooldownDuration - + final lastFeedbackSend = clock.now().subtract(cooldownDuration - const Duration(seconds: 10)); // So Feedback should get cooldown await dummyKeyValueStore.setString( diff --git a/app/test/holidays/holiday_bloc_unit_test.dart b/app/test/holidays/holiday_bloc_unit_test.dart index 9b4ad49e5..0c777f29e 100644 --- a/app/test/holidays/holiday_bloc_unit_test.dart +++ b/app/test/holidays/holiday_bloc_unit_test.dart @@ -6,6 +6,7 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:holidays/holidays.dart'; import 'package:mockito/annotations.dart'; @@ -175,7 +176,7 @@ class InMemoryHolidayStateGateway extends HolidayStateGateway { List generateHolidayList(int length) { List holidays = []; for (int i = 0; i < length; i++) { - final start = DateTime.now().add(Duration(days: i + 1)); + final start = clock.now().add(Duration(days: i + 1)); final end = start.add(Duration(days: i + 4)); holidays.add(generateHoliday(start, end)); } diff --git a/app/test/holidays/holiday_cache_test.dart b/app/test/holidays/holiday_cache_test.dart index 94bc2c696..bf0c5eef5 100644 --- a/app/test/holidays/holiday_cache_test.dart +++ b/app/test/holidays/holiday_cache_test.dart @@ -7,6 +7,7 @@ // SPDX-License-Identifier: EUPL-1.2 import 'package:built_collection/built_collection.dart'; +import 'package:clock/clock.dart'; import "package:flutter_test/flutter_test.dart"; import 'package:holidays/holidays.dart'; import 'package:key_value_store/in_memory_key_value_store.dart'; @@ -37,14 +38,14 @@ void main() { State state = const NordrheinWestfalen(); Holiday holidayInTheFuture = generateHoliday( - DateTime.now().add(const Duration(days: 1)), - DateTime.now().add(const Duration(days: 5))); + clock.now().add(const Duration(days: 1)), + clock.now().add(const Duration(days: 5))); Holiday holidayInThePast = generateHoliday( - DateTime.now().subtract(const Duration(days: 10)), - DateTime.now().subtract(const Duration(days: 5))); + clock.now().subtract(const Duration(days: 10)), + clock.now().subtract(const Duration(days: 5))); holidayCacheData = HolidayCacheData((b) => b ..holidays = ListBuilder([holidayInThePast, holidayInTheFuture]) - ..saved = DateTime.now()); + ..saved = clock.now()); kVstore.setString( HolidayCache.getKeyString(state), holidayCacheData.toJson()); @@ -66,8 +67,8 @@ void main() { expect(cacheResponse.inValidTimeframe, true); }); test("Correctly returns false", () async { - final sixtyDaysBefore = DateTime.now().subtract(const Duration(days: 60)); - final now = DateTime.now(); + final sixtyDaysBefore = clock.now().subtract(const Duration(days: 60)); + final now = clock.now(); var currentTimeReturnedToCache = sixtyDaysBefore; HolidayCache cache = HolidayCache(kVstore, getCurrentTime: () => currentTimeReturnedToCache); diff --git a/app/test/holidays/integration_test.dart b/app/test/holidays/integration_test.dart index ef379590c..68fd2bcb6 100644 --- a/app/test/holidays/integration_test.dart +++ b/app/test/holidays/integration_test.dart @@ -74,7 +74,7 @@ HolidayBloc setupBloc(MockSharezoneAppFunctions szAppFunctions, HolidayApi api = HolidayApi( CloudFunctionHolidayApiClient(szAppFunctions), getCurrentTime: () => currentTime, - ); // Return ended Holidays, as I can't manipulate DateTime.now(). This would lead to flaky tests. + ); // Return ended Holidays, as I can't manipulate clock.now(). This would lead to flaky tests. InMemoryKeyValueStore keyValueStore = InMemoryKeyValueStore(); HolidayCache cache = HolidayCache(keyValueStore, getCurrentTime: () => currentTime); diff --git a/app/test/timetable/timetable_bloc_test.dart b/app/test/timetable/timetable_bloc_test.dart index e24c8e881..25ece27c0 100644 --- a/app/test/timetable/timetable_bloc_test.dart +++ b/app/test/timetable/timetable_bloc_test.dart @@ -8,6 +8,7 @@ import 'dart:math'; +import 'package:clock/clock.dart'; import 'package:common_domain_models/common_domain_models.dart'; import 'package:date/src/date.dart'; import 'package:date/weekday.dart'; @@ -55,8 +56,8 @@ void main() { teacher: "", weekday: WeekDay.monday, weektype: WeekType.always, - startDate: Date.fromDateTime(DateTime.now()), - endDate: Date.fromDateTime(DateTime.now()), + startDate: Date.fromDateTime(clock.now()), + endDate: Date.fromDateTime(clock.now()), ); } diff --git a/app/test_goldens/dashboard/dashboard_page_test.dart b/app/test_goldens/dashboard/dashboard_page_test.dart index 87bb96918..5b1612e96 100644 --- a/app/test_goldens/dashboard/dashboard_page_test.dart +++ b/app/test_goldens/dashboard/dashboard_page_test.dart @@ -10,13 +10,14 @@ import 'dart:async'; import 'dart:convert'; import 'package:bloc_provider/bloc_provider.dart'; +import 'package:clock/clock.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:holidays/holidays.dart'; import 'package:intl/intl.dart'; -import 'package:sharezone/holidays/holiday_bloc.dart'; import 'package:sharezone/dashboard/dashboard_page.dart'; +import 'package:sharezone/holidays/holiday_bloc.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; class FakeHolidayBloc extends Fake implements HolidayBloc { @@ -42,7 +43,7 @@ void main() { final holidayBloc = FakeHolidayBloc(); addTearDown(holidayBloc.dispose); - final now = DateTime.now(); + final now = clock.now(); final firstHolidays = Holiday.fromJson(jsonEncode({ "start": DateFormat('yyyy-MM-dd').format(now), "end": "${now.year + 1}-02-01", diff --git a/lib/abgabe/abgabe_client_lib/lib/src/erstellung/bloc/homework_user_create_submissions_bloc_factory.dart b/lib/abgabe/abgabe_client_lib/lib/src/erstellung/bloc/homework_user_create_submissions_bloc_factory.dart index a84c59a35..31ce580f8 100644 --- a/lib/abgabe/abgabe_client_lib/lib/src/erstellung/bloc/homework_user_create_submissions_bloc_factory.dart +++ b/lib/abgabe/abgabe_client_lib/lib/src/erstellung/bloc/homework_user_create_submissions_bloc_factory.dart @@ -16,6 +16,7 @@ import 'package:abgabe_client_lib/src/erstellung/use_cases/datei_loescher.dart'; import 'package:abgabe_client_lib/src/erstellung/use_cases/datei_umbenenner.dart'; import 'package:abgabe_http_api/api.dart'; import 'package:bloc_base/bloc_base.dart'; +import 'package:clock/clock.dart'; import 'package:common_domain_models/common_domain_models.dart'; class HomeworkUserCreateSubmissionsBlocFactory extends BlocBase { @@ -59,7 +60,7 @@ class HomeworkUserCreateSubmissionsBlocFactory extends BlocBase { umbenenner, veroeffentlicher, gateway.streamAbgabezeitpunktFuerHausaufgabe(id), - () => DateTime.now(), + () => clock.now(), ); } diff --git a/lib/abgabe/abgabe_client_lib/lib/src/erstellung/cloud_storage_abgabedatei_uploader.dart b/lib/abgabe/abgabe_client_lib/lib/src/erstellung/cloud_storage_abgabedatei_uploader.dart index 82f0f8914..fda44a91c 100644 --- a/lib/abgabe/abgabe_client_lib/lib/src/erstellung/cloud_storage_abgabedatei_uploader.dart +++ b/lib/abgabe/abgabe_client_lib/lib/src/erstellung/cloud_storage_abgabedatei_uploader.dart @@ -12,7 +12,7 @@ import 'package:abgabe_client_lib/src/erstellung/datei_upload_prozess.dart'; import 'package:abgabe_client_lib/src/erstellung/local_file_saver.dart'; import 'package:abgabe_client_lib/src/models/models.dart'; import 'package:abgabe_http_api/api/abgabedatei_api.dart'; - +import 'package:clock/clock.dart'; import 'package:crash_analytics/crash_analytics.dart'; import 'package:files_basics/local_file.dart'; import 'package:filesharing_logic/file_uploader.dart'; @@ -20,7 +20,7 @@ import 'package:filesharing_logic/file_uploader.dart'; import 'uploader/abgabedatei_uploader.dart'; import 'use_cases/abgabedatei_hinzufueger.dart'; -DateTime _lastUploaded = DateTime.now(); +DateTime _lastUploaded = clock.now(); class CloudStorageAbgabedateiUploader extends AbgabedateiUploader { final FileUploader fileUploader; @@ -57,11 +57,11 @@ class CloudStorageAbgabedateiUploader extends AbgabedateiUploader { /// passieren kann, dass das hinzufügen einer Datei "überschrieben" /// also sozusagen rückgängig gemacht wird, wenn die Anfragen parallel /// verarbeitet werden. - while (DateTime.now().difference(_lastUploaded).abs() < + while (clock.now().difference(_lastUploaded).abs() < const Duration(milliseconds: 900)) { await Future.delayed(const Duration(milliseconds: 300)); } - _lastUploaded = DateTime.now(); + _lastUploaded = clock.now(); await _fuegeAbgabedateireferenzZuAbgabeHinzu(befehl); } catch (e, s) { await _logAbgabedateireferenzHinzufuegeError(e, s); diff --git a/lib/abgabe/abgabe_client_lib/pubspec.lock b/lib/abgabe/abgabe_client_lib/pubspec.lock index 36fc3e7d2..f73c2b9af 100644 --- a/lib/abgabe/abgabe_client_lib/pubspec.lock +++ b/lib/abgabe/abgabe_client_lib/pubspec.lock @@ -142,7 +142,7 @@ packages: source: hosted version: "1.7.0" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/abgabe/abgabe_client_lib/pubspec.yaml b/lib/abgabe/abgabe_client_lib/pubspec.yaml index 6b6432e63..7ac4d8412 100644 --- a/lib/abgabe/abgabe_client_lib/pubspec.yaml +++ b/lib/abgabe/abgabe_client_lib/pubspec.yaml @@ -39,6 +39,7 @@ dependencies: meta: ^1.1.8 rxdart: ^0.27.1 collection: ^1.17.2 + clock: ^1.1.1 dev_dependencies: flutter_test: diff --git a/lib/abgabe/abgabe_client_lib/test/bloc_test.dart b/lib/abgabe/abgabe_client_lib/test/bloc_test.dart index 5a6121618..b2d6d0e46 100644 --- a/lib/abgabe/abgabe_client_lib/test/bloc_test.dart +++ b/lib/abgabe/abgabe_client_lib/test/bloc_test.dart @@ -19,15 +19,14 @@ import 'package:abgabe_client_lib/src/erstellung/use_cases/datei_loescher.dart'; import 'package:abgabe_client_lib/src/erstellung/use_cases/datei_umbenenner.dart'; import 'package:abgabe_client_lib/src/erstellung/views.dart'; import 'package:abgabe_client_lib/src/models/models.dart'; - import 'package:async/async.dart'; +import 'package:clock/clock.dart'; import 'package:common_domain_models/common_domain_models.dart'; import 'package:files_basics/files_models.dart'; import 'package:files_basics/local_file.dart'; - +import 'package:flutter_test/flutter_test.dart'; import 'package:random_string/random_string.dart'; import 'package:rxdart/subjects.dart'; -import 'package:flutter_test/flutter_test.dart'; void main() { group( @@ -753,9 +752,9 @@ void main() { }); test('Die Dateien werden nach hinzufuegedatum sortiert.', () async { - final now = DateTime.now(); + final now = clock.now(); abgabezeitpunktStream.add(now.add(const Duration(days: 20))); - kriegeAktuelleZeit = () => DateTime.now(); + kriegeAktuelleZeit = () => clock.now(); useCases.abgabe.add( erstelleAbgabenModelSnapshot(abgegeben: false, abgabedateien: [ @@ -853,7 +852,7 @@ HochgeladeneAbgabedatei hochgeladeneAbgabedatei({ groesse: Dateigroesse(12345), downloadUrl: DateiDownloadUrl('https://some-url.com'), // Sollte letzte sein (auch wenn es eigentlich nicht sein) - erstellungsdatum: erstellungsdatum ?? DateTime.now(), + erstellungsdatum: erstellungsdatum ?? clock.now(), ); } @@ -864,7 +863,7 @@ ErstellerAbgabeModelSnapshot erstelleAbgabenModelSnapshot( abgabeId: AbgabeId( AbgabezielId.homework(HomeworkId('ValidHomeworkId')), UserId('ValidUserId')), - abgegebenUm: abgegeben ? DateTime.now() : null, + abgegebenUm: abgegeben ? clock.now() : null, abgabedateien: abgabedateien) .toSnapshot(); } diff --git a/lib/authentification/authentification_qrcode/lib/src/logic/qr_code_user_authenticator.dart b/lib/authentification/authentification_qrcode/lib/src/logic/qr_code_user_authenticator.dart index b0b311c50..5c1e513e9 100644 --- a/lib/authentification/authentification_qrcode/lib/src/logic/qr_code_user_authenticator.dart +++ b/lib/authentification/authentification_qrcode/lib/src/logic/qr_code_user_authenticator.dart @@ -7,7 +7,9 @@ // SPDX-License-Identifier: EUPL-1.2 import 'package:app_functions/sharezone_app_functions.dart'; +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; + import '../models/qr_sign_in_document.dart'; import '../models/qr_sign_in_state.dart'; @@ -48,7 +50,7 @@ class QrCodeUserAuthenticator { final qrSignInDocument = QrSignInDocument( qrId: qrId, publicKey: publicKey, - created: DateTime.now(), + created: clock.now(), ); _qrSignInCollection.doc(qrId).set(qrSignInDocument.toData()); return qrId; diff --git a/lib/authentification/authentification_qrcode/pubspec.lock b/lib/authentification/authentification_qrcode/pubspec.lock index 6d85126eb..7bcf2d604 100644 --- a/lib/authentification/authentification_qrcode/pubspec.lock +++ b/lib/authentification/authentification_qrcode/pubspec.lock @@ -101,7 +101,7 @@ packages: source: hosted version: "1.3.0" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/authentification/authentification_qrcode/pubspec.yaml b/lib/authentification/authentification_qrcode/pubspec.yaml index 7c0883ec7..7373cdd09 100644 --- a/lib/authentification/authentification_qrcode/pubspec.yaml +++ b/lib/authentification/authentification_qrcode/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: fast_rsa: ^3.6.1 firebase_auth: ^4.7.3 rxdart: ^0.27.1 + clock: ^1.1.1 dev_dependencies: flutter_test: diff --git a/lib/cloud_firestore_helper/lib/src/cloud_firestore_helper.dart b/lib/cloud_firestore_helper/lib/src/cloud_firestore_helper.dart index d8d6b968a..8e8c3ca27 100644 --- a/lib/cloud_firestore_helper/lib/src/cloud_firestore_helper.dart +++ b/lib/cloud_firestore_helper/lib/src/cloud_firestore_helper.dart @@ -6,6 +6,8 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; + typedef ObjectMapBuilder = T Function(String key, dynamic decodedMapValue); typedef ObjectListBuilder = T Function(dynamic decodedMapValue); @@ -42,7 +44,7 @@ List decodeList(dynamic data, ObjectListBuilder builder) { /// behavior is legacy and shouldn't be used anymore. DateTime dateTimeFromTimestamp(dynamic timestamp) { final dateTime = dateTimeFromTimestampOrNull(timestamp); - return dateTime ?? DateTime.now(); + return dateTime ?? clock.now(); } DateTime? dateTimeFromTimestampOrNull(dynamic timestamp) { diff --git a/lib/cloud_firestore_helper/pubspec.lock b/lib/cloud_firestore_helper/pubspec.lock index 60a125941..b1201c533 100644 --- a/lib/cloud_firestore_helper/pubspec.lock +++ b/lib/cloud_firestore_helper/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + clock: + dependency: "direct main" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" flutter_lints: dependency: transitive description: diff --git a/lib/cloud_firestore_helper/pubspec.yaml b/lib/cloud_firestore_helper/pubspec.yaml index 266976927..b46649772 100644 --- a/lib/cloud_firestore_helper/pubspec.yaml +++ b/lib/cloud_firestore_helper/pubspec.yaml @@ -20,3 +20,6 @@ environment: dev_dependencies: sharezone_lints: path: ../sharezone_lints + +dependencies: + clock: ^1.1.1 diff --git a/lib/date/lib/src/date.dart b/lib/date/lib/src/date.dart index f782ed740..664a4f00f 100644 --- a/lib/date/lib/src/date.dart +++ b/lib/date/lib/src/date.dart @@ -6,7 +6,9 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:intl/intl.dart'; + import 'weekday.dart'; class Date { @@ -31,7 +33,7 @@ class Date { return Date._(dateTime.toIso8601String().substring(0, 10)); } - factory Date.today() => Date.fromDateTime(DateTime.now()); + factory Date.today() => Date.fromDateTime(clock.now()); /// Gibt das aktuelle [Date] als Stream zurück. /// diff --git a/lib/date/pubspec.lock b/lib/date/pubspec.lock index ae3524d2f..e6e271e78 100644 --- a/lib/date/pubspec.lock +++ b/lib/date/pubspec.lock @@ -10,7 +10,7 @@ packages: source: hosted version: "1.3.0" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/date/pubspec.yaml b/lib/date/pubspec.yaml index d2e193fd2..020f1fc04 100644 --- a/lib/date/pubspec.yaml +++ b/lib/date/pubspec.yaml @@ -19,6 +19,7 @@ dependencies: rxdart: ^0.27.1 flutter: sdk: flutter + clock: ^1.1.1 dev_dependencies: sharezone_lints: diff --git a/lib/filesharing/filesharing_logic/lib/src/models/cloud_file.dart b/lib/filesharing/filesharing_logic/lib/src/models/cloud_file.dart index ae1416d05..a9f8217eb 100644 --- a/lib/filesharing/filesharing_logic/lib/src/models/cloud_file.dart +++ b/lib/filesharing/filesharing_logic/lib/src/models/cloud_file.dart @@ -6,9 +6,10 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:files_basics/files_models.dart'; import 'package:cloud_firestore_helper/cloud_firestore_helper.dart'; +import 'package:files_basics/files_models.dart'; import 'change_activity.dart'; import 'folder_path.dart'; @@ -83,7 +84,7 @@ class CloudFile { name: '', downloadURL: null, thumbnailURL: null, - createdOn: DateTime.now(), + createdOn: clock.now(), sizeBytes: null, fileFormat: FileFormat.unknown, forUsers: {}, diff --git a/lib/filesharing/filesharing_logic/pubspec.lock b/lib/filesharing/filesharing_logic/pubspec.lock index 6a09a158d..730287124 100644 --- a/lib/filesharing/filesharing_logic/pubspec.lock +++ b/lib/filesharing/filesharing_logic/pubspec.lock @@ -64,7 +64,7 @@ packages: source: hosted version: "1.7.0" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/filesharing/filesharing_logic/pubspec.yaml b/lib/filesharing/filesharing_logic/pubspec.yaml index 6dd03310f..97a6c03fc 100644 --- a/lib/filesharing/filesharing_logic/pubspec.yaml +++ b/lib/filesharing/filesharing_logic/pubspec.yaml @@ -33,6 +33,7 @@ dependencies: permission_handler: ^11.1.0 helper_functions: path: ../../helper_functions + clock: ^1.1.1 dev_dependencies: flutter_test: diff --git a/lib/firebase_hausaufgabenheft_logik/lib/src/homework_dto.dart b/lib/firebase_hausaufgabenheft_logik/lib/src/homework_dto.dart index f36ba3d13..aba542866 100644 --- a/lib/firebase_hausaufgabenheft_logik/lib/src/homework_dto.dart +++ b/lib/firebase_hausaufgabenheft_logik/lib/src/homework_dto.dart @@ -6,9 +6,10 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:collection/collection.dart'; import 'package:cloud_firestore_helper/cloud_firestore_helper.dart'; +import 'package:collection/collection.dart'; class HomeworkDto { final String id; @@ -128,7 +129,7 @@ class HomeworkDto { description: "", withSubmissions: false, submitters: [], - todoUntil: DateTime.now(), + todoUntil: clock.now(), createdOn: null, attachments: [], private: false, diff --git a/lib/firebase_hausaufgabenheft_logik/pubspec.lock b/lib/firebase_hausaufgabenheft_logik/pubspec.lock index a33cad724..0d6e78ba9 100644 --- a/lib/firebase_hausaufgabenheft_logik/pubspec.lock +++ b/lib/firebase_hausaufgabenheft_logik/pubspec.lock @@ -65,7 +65,7 @@ packages: source: hosted version: "1.3.0" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/firebase_hausaufgabenheft_logik/pubspec.yaml b/lib/firebase_hausaufgabenheft_logik/pubspec.yaml index 4d7832a02..5fc1a355b 100644 --- a/lib/firebase_hausaufgabenheft_logik/pubspec.yaml +++ b/lib/firebase_hausaufgabenheft_logik/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: cloud_firestore: ^4.8.5 flutter: sdk: flutter + clock: ^1.1.1 dev_dependencies: rxdart: ^0.27.1 diff --git a/lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart b/lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart index bec652661..11c176af8 100644 --- a/lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart +++ b/lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart @@ -8,11 +8,13 @@ import 'dart:async'; +import 'package:clock/clock.dart'; import 'package:common_domain_models/common_domain_models.dart'; import 'package:firebase_hausaufgabenheft_logik/src/realtime_updating_lazy_loading_controller.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:rxdart/subjects.dart' as rx; import 'package:hausaufgabenheft_logik/hausaufgabenheft_logik.dart'; +import 'package:rxdart/subjects.dart' as rx; + import 'in_memory_homework_loader.dart'; class ReportingInMemoryHomeworkLoader extends InMemoryHomeworkLoader { @@ -31,7 +33,7 @@ List listOfHomeworksWithLength(int length) => List.generate( length, (index) => HomeworkReadModel( id: HomeworkId("$index"), - todoDate: DateTime.now(), + todoDate: clock.now(), status: CompletionStatus.completed, subject: Subject("Mathe", abbreviation: 'Ma'), title: const Title("ABC"), diff --git a/lib/group_domain_models/lib/src/models/member.dart b/lib/group_domain_models/lib/src/models/member.dart index 4474fbeb5..b848a23a5 100644 --- a/lib/group_domain_models/lib/src/models/member.dart +++ b/lib/group_domain_models/lib/src/models/member.dart @@ -6,9 +6,10 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; +import 'package:cloud_firestore_helper/cloud_firestore_helper.dart'; import 'package:common_domain_models/common_domain_models.dart'; import 'package:flutter/foundation.dart'; -import 'package:cloud_firestore_helper/cloud_firestore_helper.dart'; import 'package:user/user.dart'; import 'member_role.dart'; @@ -41,7 +42,7 @@ class MemberData { abbreviation: generateAbbreviation(user.name), role: role, typeOfUser: user.typeOfUser, - joinedOn: DateTime.now(), + joinedOn: clock.now(), ); } diff --git a/lib/group_domain_models/pubspec.lock b/lib/group_domain_models/pubspec.lock index 74dbd539f..011f5c53f 100644 --- a/lib/group_domain_models/pubspec.lock +++ b/lib/group_domain_models/pubspec.lock @@ -64,7 +64,7 @@ packages: source: hosted version: "1.3.0" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/group_domain_models/pubspec.yaml b/lib/group_domain_models/pubspec.yaml index 212775cd9..ce2748f3c 100644 --- a/lib/group_domain_models/pubspec.yaml +++ b/lib/group_domain_models/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: path: ../design flutter: sdk: flutter + clock: ^1.1.1 dev_dependencies: flutter_test: diff --git a/lib/hausaufgabenheft_logik/lib/src/models/date.dart b/lib/hausaufgabenheft_logik/lib/src/models/date.dart index 91730749b..d0f1896e6 100644 --- a/lib/hausaufgabenheft_logik/lib/src/models/date.dart +++ b/lib/hausaufgabenheft_logik/lib/src/models/date.dart @@ -6,6 +6,8 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; + class Date implements Comparable { final int day; final int month; @@ -18,7 +20,7 @@ class Date implements Comparable { }); factory Date.now() { - final now = DateTime.now(); + final now = clock.now(); return Date(day: now.day, month: now.month, year: now.year); } diff --git a/lib/hausaufgabenheft_logik/lib/src/setup/create_homework_page_bloc.dart b/lib/hausaufgabenheft_logik/lib/src/setup/create_homework_page_bloc.dart index a4a61d01f..cfac84e32 100644 --- a/lib/hausaufgabenheft_logik/lib/src/setup/create_homework_page_bloc.dart +++ b/lib/hausaufgabenheft_logik/lib/src/setup/create_homework_page_bloc.dart @@ -6,19 +6,20 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:hausaufgabenheft_logik/src/homework_completion/homework_page_completion_dispatcher.dart'; -import 'package:hausaufgabenheft_logik/src/student_homework_page_bloc/homework_sorting_cache.dart'; import 'package:hausaufgabenheft_logik/src/open_homeworks/open_homework_list_bloc/open_homework_list_bloc.dart'; import 'package:hausaufgabenheft_logik/src/open_homeworks/open_homework_view_bloc/open_homework_view_bloc.dart'; +import 'package:hausaufgabenheft_logik/src/student_homework_page_bloc/homework_sorting_cache.dart'; import '../completed_homeworks/completed_homeworks_view_bloc/completed_homeworks_view_bloc.dart'; import '../completed_homeworks/lazy_loading_completed_homeworks_bloc/lazy_loading_completed_homeworks_bloc.dart'; import '../completed_homeworks/views/completed_homework_list_view_factory.dart'; -import '../student_homework_page_bloc/student_homework_page_bloc.dart'; import '../models/homework/models_used_by_homework.dart'; import '../open_homeworks/sort_and_subcategorization/sort_and_subcategorizer.dart'; import '../open_homeworks/sort_and_subcategorization/subcategorizer_factory.dart'; import '../open_homeworks/views/open_homework_list_view_factory.dart'; +import '../student_homework_page_bloc/student_homework_page_bloc.dart'; import '../views/student_homework_view_factory.dart'; import 'config.dart'; import 'dependencies.dart'; @@ -54,6 +55,6 @@ HomeworkPageBloc createHomeworkPageBloc( completedHomeworksViewBloc: completedHomeworksViewBloc, homeworkCompletionReceiver: homeworkPageCompletionReceiver, homeworkSortingCache: HomeworkSortingCache(dependencies.keyValueStore), - getCurrentDateTime: dependencies.getCurrentDateTime ?? () => DateTime.now(), + getCurrentDateTime: dependencies.getCurrentDateTime ?? () => clock.now(), ); } diff --git a/lib/hausaufgabenheft_logik/pubspec.lock b/lib/hausaufgabenheft_logik/pubspec.lock index 9dba12a3b..7749177ac 100644 --- a/lib/hausaufgabenheft_logik/pubspec.lock +++ b/lib/hausaufgabenheft_logik/pubspec.lock @@ -65,7 +65,7 @@ packages: source: hosted version: "2.1.1" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/hausaufgabenheft_logik/pubspec.yaml b/lib/hausaufgabenheft_logik/pubspec.yaml index fe0e71437..c42253741 100644 --- a/lib/hausaufgabenheft_logik/pubspec.yaml +++ b/lib/hausaufgabenheft_logik/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: # For teacher fake bloc currently in use (can be removed when bloc is implemented) # https://gitlab.com/codingbrain/sharezone/sharezone-app/-/issues/1460 random_string: ^2.0.1 + clock: ^1.1.1 dev_dependencies: async: ^2.11.0 diff --git a/lib/hausaufgabenheft_logik/test/date/date_test.dart b/lib/hausaufgabenheft_logik/test/date/date_test.dart index 3b5751b71..f1b3db911 100644 --- a/lib/hausaufgabenheft_logik/test/date/date_test.dart +++ b/lib/hausaufgabenheft_logik/test/date/date_test.dart @@ -6,6 +6,7 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'package:clock/clock.dart'; import 'package:hausaufgabenheft_logik/src/models/date.dart'; import 'package:test/test.dart'; @@ -50,7 +51,7 @@ void main() { test('Date.now', () { final now = Date.now(); - var nowDateTime = DateTime.now(); + var nowDateTime = clock.now(); expect(now.year, nowDateTime.year); expect(now.month, nowDateTime.month); expect(now.day, nowDateTime.day); diff --git a/lib/hausaufgabenheft_logik/test/homework_page_bloc_test.dart b/lib/hausaufgabenheft_logik/test/homework_page_bloc_test.dart index 815ce3a43..a1652b449 100644 --- a/lib/hausaufgabenheft_logik/test/homework_page_bloc_test.dart +++ b/lib/hausaufgabenheft_logik/test/homework_page_bloc_test.dart @@ -10,6 +10,7 @@ import 'dart:async'; import 'dart:developer'; import 'package:bloc/bloc.dart'; +import 'package:clock/clock.dart'; import 'package:hausaufgabenheft_logik/hausaufgabenheft_logik.dart'; import 'package:hausaufgabenheft_logik/hausaufgabenheft_logik_setup.dart'; import 'package:hausaufgabenheft_logik/src/completed_homeworks/completed_homeworks_view_bloc/completed_homeworks_view_bloc.dart' @@ -338,7 +339,7 @@ void main() { 'should show dialog to check all completed homework when more than 2 open overdue homeworks', () async { final yesterday = - Date.fromDateTime(DateTime.now().subtract(const Duration(days: 1))); + Date.fromDateTime(clock.now().subtract(const Duration(days: 1))); final homeworks = List.generate( 3, (_) => createHomework(done: false, todoDate: yesterday)); @@ -352,9 +353,9 @@ void main() { 'does not show dialog to check all completed homework with less than 3 overdue homeworks', () async { final yesterday = - Date.fromDateTime(DateTime.now().subtract(const Duration(days: 1))); + Date.fromDateTime(clock.now().subtract(const Duration(days: 1))); final tomorrow = - Date.fromDateTime(DateTime.now().add(const Duration(days: 1))); + Date.fromDateTime(clock.now().add(const Duration(days: 1))); final homeworks = [ ...List.generate( diff --git a/lib/holidays/lib/src/holiday_cache.dart b/lib/holidays/lib/src/holiday_cache.dart index 853536a46..f2c1e159f 100644 --- a/lib/holidays/lib/src/holiday_cache.dart +++ b/lib/holidays/lib/src/holiday_cache.dart @@ -7,7 +7,9 @@ // SPDX-License-Identifier: EUPL-1.2 import 'package:built_collection/built_collection.dart'; +import 'package:clock/clock.dart'; import 'package:key_value_store/key_value_store.dart'; + import 'api/holiday.dart'; import 'state.dart'; @@ -21,7 +23,7 @@ class HolidayCache { HolidayCache(this.cache, {this.maxValidDurationTillLastSaved = const Duration(days: 30), this.getCurrentTime}) { - getCurrentTime ??= () => DateTime.now(); + getCurrentTime ??= () => clock.now(); } CacheResponse? load(State state) { diff --git a/lib/holidays/pubspec.lock b/lib/holidays/pubspec.lock index 87635c68d..1c7332ce7 100644 --- a/lib/holidays/pubspec.lock +++ b/lib/holidays/pubspec.lock @@ -144,7 +144,7 @@ packages: source: hosted version: "2.0.3" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/holidays/pubspec.yaml b/lib/holidays/pubspec.yaml index c0fd2c953..3a806cd80 100644 --- a/lib/holidays/pubspec.yaml +++ b/lib/holidays/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: cloud_functions: ^4.4.0 app_functions: path: ../app_functions + clock: ^1.1.1 dev_dependencies: # We need to add the `flutter` package as dev dependency as workaround for the diff --git a/lib/sharezone_widgets/lib/src/widgets.dart b/lib/sharezone_widgets/lib/src/widgets.dart index 8e014cae1..630708dc5 100644 --- a/lib/sharezone_widgets/lib/src/widgets.dart +++ b/lib/sharezone_widgets/lib/src/widgets.dart @@ -9,9 +9,10 @@ import 'dart:async'; import 'dart:developer'; +import 'package:clock/clock.dart'; import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; import 'package:helper_functions/helper_functions.dart'; +import 'package:intl/intl.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; export 'prefilled_text_field.dart'; @@ -66,7 +67,7 @@ class DatePicker extends StatelessWidget { Future _selectDate(BuildContext context) async { FocusManager.instance.primaryFocus?.unfocus(); final DateTime tomorrow = - DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day) + DateTime(clock.now().year, clock.now().month, clock.now().day) .add(const Duration(days: 1)); final DateTime? picked = await showDatePicker( context: context, diff --git a/lib/sharezone_widgets/pubspec.lock b/lib/sharezone_widgets/pubspec.lock index 9ec132a39..7bfe6c06c 100644 --- a/lib/sharezone_widgets/pubspec.lock +++ b/lib/sharezone_widgets/pubspec.lock @@ -41,7 +41,7 @@ packages: source: hosted version: "1.3.0" clock: - dependency: transitive + dependency: "direct main" description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf diff --git a/lib/sharezone_widgets/pubspec.yaml b/lib/sharezone_widgets/pubspec.yaml index 554673a67..07f19a6d3 100644 --- a/lib/sharezone_widgets/pubspec.yaml +++ b/lib/sharezone_widgets/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: rxdart: ^0.27.1 flutter: sdk: flutter + clock: ^1.1.1 dev_dependencies: flutter_test: diff --git a/tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart b/tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart index a0151f3eb..541d78d0d 100644 --- a/tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart +++ b/tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart @@ -9,6 +9,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:clock/clock.dart'; import 'package:sz_repo_cli/src/common/common.dart'; /// Run a task via [runTaskForPackage] for many [Package] concurrently. @@ -91,7 +92,7 @@ abstract class ConcurrentCommand extends CommandBase { : null; final taskRunner = ConcurrentPackageTaskRunner( - getCurrentDateTime: () => DateTime.now(), + getCurrentDateTime: () => clock.now(), ); final res = taskRunner diff --git a/tools/sz_repo_cli/lib/src/common/src/concurrent_package_task_runner.dart b/tools/sz_repo_cli/lib/src/common/src/concurrent_package_task_runner.dart index 5a647a8cb..5f651cd1d 100644 --- a/tools/sz_repo_cli/lib/src/common/src/concurrent_package_task_runner.dart +++ b/tools/sz_repo_cli/lib/src/common/src/concurrent_package_task_runner.dart @@ -10,6 +10,7 @@ import 'dart:async'; import 'dart:collection'; import 'dart:io'; +import 'package:clock/clock.dart'; import 'package:rxdart/subjects.dart'; import 'package:rxdart/transformers.dart'; import 'package:sz_repo_cli/src/common/common.dart'; @@ -20,7 +21,7 @@ class ConcurrentPackageTaskRunner { ConcurrentPackageTaskRunner({ DateTime Function()? getCurrentDateTime, }) { - _getCurrentDateTime = getCurrentDateTime ?? () => DateTime.now(); + _getCurrentDateTime = getCurrentDateTime ?? () => clock.now(); } /// Run [runTask] for every [Package] emitted by the [packageStream]. diff --git a/tools/sz_repo_cli/pubspec.lock b/tools/sz_repo_cli/pubspec.lock index c7019dd11..fc669c965 100644 --- a/tools/sz_repo_cli/pubspec.lock +++ b/tools/sz_repo_cli/pubspec.lock @@ -57,6 +57,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.0" + clock: + dependency: "direct main" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" collection: dependency: transitive description: diff --git a/tools/sz_repo_cli/pubspec.yaml b/tools/sz_repo_cli/pubspec.yaml index 40cadc575..576be3455 100644 --- a/tools/sz_repo_cli/pubspec.yaml +++ b/tools/sz_repo_cli/pubspec.yaml @@ -34,6 +34,7 @@ dependencies: process: ^5.0.1 process_runner: ^4.1.4 file: ^7.0.0 + clock: ^1.1.1 dev_dependencies: sharezone_lints: