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

add atStartOfDay() extension

parent 1a208873
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,12 @@ extension DateExtension on DateTime {
return '$dd.$mm.$year';
}
DateTime atStartOfDay() {
return DateTime(year, month, day);
}
DateTime atStartOfWeek() {
final date = subtract(Duration(days: weekday - 1));
return DateTime(date.year, date.month, date.day);
return date.atStartOfDay();
}
}
......@@ -30,4 +30,14 @@ void main() {
expect(startOfWeek, startOfNextMonday);
});
test('Start of day at 00:00', () {
final startOfWeek = DateTime(2023, 3, 21, 0, 0).atStartOfDay();
expect(startOfWeek, DateTime(2023, 3, 21, 0, 0));
});
test('Start of day at 23:59', () {
final startOfWeek = DateTime(2023, 3, 21, 23, 59).atStartOfDay();
expect(startOfWeek, DateTime(2023, 3, 21, 00, 00));
});
}
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