Skip to content

Commit

Permalink
add display dates for weeks when schedule is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
smart7even committed Aug 18, 2024
1 parent 49c2580 commit 429685d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
8 changes: 8 additions & 0 deletions lib/common/utils/date_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ DateTime getStartOfStudyWeek(int week, DateTime nowTime) {
return startWeekDate;
}

DateTime getEndOfStudyWeek(int week, DateTime nowTime) {
return getStartOfStudyWeek(week, nowTime).add(
const Duration(
days: 6,
),
);
}

DateTime getStartOfStudyYearDate(DateTime nowTime) {
if (nowTime.month >= kSeptemberMonthNumber) {
return getWeekStart(
Expand Down
2 changes: 1 addition & 1 deletion lib/feature/schedule/domain/schedule_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ScheduleTransformer {
for (final daySchedule in schedule.daySchedules) {
result += DateFormat('dd.MM.yyyy').format(daySchedule.day);
result += space;
result += DateFormat('EEE', 'ru').format(daySchedule.day);
result += DateFormat('EEE').format(daySchedule.day);
result += newLine;

if (daySchedule.lessons.isEmpty) {
Expand Down
18 changes: 18 additions & 0 deletions lib/feature/schedule/widget/schedule_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,30 @@ class ScheduleWidget extends StatelessWidget {
}

if (currentSchedule.daySchedules.isEmpty) {
final dateFormat = DateFormat(
'dd MMMM yyyy',
);
final currentTime = DateTime.now();
final weekStart = dateFormat.format(
getStartOfStudyWeek(
currentSchedule.week,
currentTime,
),
);
final weekEnd = dateFormat.format(
getEndOfStudyWeek(
currentSchedule.week,
currentTime,
),
);

return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(AppLocalizations.of(context)!.noSchedule),
Text('$weekStart - $weekEnd'),
const SizedBox(
height: 8,
),
Expand Down
11 changes: 7 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:home_widget/home_widget.dart';
import 'package:intl/intl.dart';
import 'package:l/l.dart';
import 'package:octopus/octopus.dart';
import 'package:uneconly/common/app_scroll_configuration.dart';
import 'package:uneconly/common/logging/logging_repository.dart';
import 'package:uneconly/common/logging/logging_repository_factory.dart';
import 'package:uneconly/common/model/dependencies.dart';
import 'package:uneconly/common/routing/routes.dart';
import 'package:uneconly/common/util/error_util.dart';
Expand Down Expand Up @@ -94,12 +94,12 @@ class _MyAppState extends State<MyApp> {

HomeWidget.setAppGroupId('group.roadmapik.test');

// TODO: add multiple language support
Intl.defaultLocale = 'ru';

final defaultLocale = Platform.localeName;
locale = defaultLocale.split('_')[0];

const defaultTheme = 'blue';
theme = defaultTheme;

dependencies.settingsRepository.getLanguage().then(
(value) {
if (value != null) {
Expand All @@ -118,6 +118,9 @@ class _MyAppState extends State<MyApp> {
});
});

const defaultTheme = 'blue';
theme = defaultTheme;

dependencies.settingsRepository.getTheme().then(
(value) {
if (value != null) {
Expand Down
6 changes: 6 additions & 0 deletions test/date_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ void main() {
expect(getStartOfStudyWeek(36, nowTime), equals(DateTime(2023, 5, 1)));
});

test('getEndOfStudyWeek returns end of study week', () {
final nowTime = DateTime(2024, 8, 18, 16, 10, 11);

expect(getEndOfStudyWeek(51, nowTime), equals(DateTime(2024, 8, 18)));
});

test('getWeekStart returns start of week', () {
final nowTime = DateTime(2023, 5, 6, 21, 49, 11);

Expand Down

0 comments on commit 429685d

Please sign in to comment.