2023-02-24 20:30:51 +01:00
|
|
|
import 'package:smoke_cess_app/service/settings_service.dart';
|
|
|
|
import 'package:timezone/timezone.dart';
|
|
|
|
|
|
|
|
const int trainingTime = 40;
|
|
|
|
|
|
|
|
const weekDays = {
|
|
|
|
"Montag": 1,
|
|
|
|
"Dienstag": 2,
|
|
|
|
"Mittwoch": 3,
|
|
|
|
"Donnerstag": 4,
|
|
|
|
"Freitag": 5,
|
|
|
|
"Samstag": 6,
|
|
|
|
"Sonntag": 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
Future<List<TZDateTime>> getDatesforAll() async {
|
|
|
|
List<TZDateTime> allDates = [];
|
|
|
|
List<TZDateTime> moodDates = await getDatesforMood();
|
|
|
|
List<TZDateTime> sleepDates = await getDatesforSleep();
|
|
|
|
allDates.addAll(moodDates);
|
|
|
|
allDates.addAll(sleepDates);
|
|
|
|
return allDates;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<TZDateTime>> getDatesforMood() async {
|
|
|
|
final List<String>? selectedDays = await getMoodQueryDaysCategories();
|
|
|
|
final int? selectedHours = await getMoodQueryHours();
|
|
|
|
final int? selectedMinutes = await getMoodQueryMinutes();
|
|
|
|
return createTZDateTimes(selectedDays, selectedHours, selectedMinutes);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<TZDateTime>> getDatesforSleep() async {
|
|
|
|
final List<String>? selectedDays = await getSleepQueryDaysCategories();
|
|
|
|
final int? selectedHours = await getSleepQueryHours();
|
|
|
|
final int? selectedMinutes = await getSleepQueryMinutes();
|
|
|
|
return createTZDateTimes(selectedDays, selectedHours, selectedMinutes);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<TZDateTime> createTZDateTimes(
|
|
|
|
List<String>? selectedDays, int? selectedHours, int? selectedMinutes) {
|
|
|
|
List<TZDateTime> tzDateTimes = [];
|
|
|
|
if (selectedDays == null ||
|
|
|
|
selectedHours == null ||
|
|
|
|
selectedMinutes == null) {
|
|
|
|
return tzDateTimes;
|
|
|
|
}
|
|
|
|
final Iterable<int?> selectedDaysInt =
|
|
|
|
selectedDays.map((day) => weekDays[day]);
|
|
|
|
for (int i = 0; i < trainingTime; i++) {
|
|
|
|
final DateTime date = DateTime.now().add(Duration(days: i));
|
2023-02-25 14:39:05 +01:00
|
|
|
if (selectedDaysInt.contains(date.weekday) &&
|
|
|
|
date.isAfter(DateTime.now())) {
|
2023-02-24 20:30:51 +01:00
|
|
|
tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day,
|
|
|
|
selectedHours, selectedMinutes, 0, 0, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tzDateTimes;
|
|
|
|
}
|