Skip to content
Snippets Groups Projects
Commit 1a208873 authored by doodlezucc's avatar doodlezucc
Browse files

improve start of week calculation

parent 429bd8af
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ extension DateExtension on DateTime {
}
DateTime atStartOfWeek() {
return subtract(Duration(days: weekday - 1));
final date = subtract(Duration(days: weekday - 1));
return DateTime(date.year, date.month, date.day);
}
}
import 'package:better_untis/util/date_extension.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
final startOfMonday = DateTime(2023, 3, 20, 0, 0);
test('Start of week at start of monday', () {
final startOfWeek = startOfMonday.atStartOfWeek();
expect(startOfWeek, startOfMonday);
});
test('Start of week at end of tuesday', () {
final endOfTuesday = DateTime(2023, 3, 21, 23, 59);
final startOfWeek = endOfTuesday.atStartOfWeek();
expect(startOfWeek, startOfMonday);
});
test('Start of week at end of sunday', () {
final endOfSaturday = DateTime(2023, 3, 26, 23, 59);
final startOfWeek = endOfSaturday.atStartOfWeek();
expect(startOfWeek, startOfMonday);
});
test('Start of week at end of next monday', () {
final startOfNextMonday = DateTime(2023, 3, 27, 0, 0);
final startOfWeek = startOfNextMonday.atStartOfWeek();
expect(startOfWeek, startOfNextMonday);
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment