getDateTimeWeekStart function
Returns the start of the week using time
as reference.
weekFirstDay
the desired first day of week for computation behavior.
time
if null uses DateTime.now .
Implementation
DateTime getDateTimeWeekStart([DateTimeWeekDay? weekFirstDay, DateTime? time]) {
weekFirstDay ??= DateTimeWeekDay.monday;
time ??= DateTime.now();
var weekFirstDayIndex = getDateTimeWeekDayIndex(weekFirstDay);
while (time!.weekday != weekFirstDayIndex) {
time = time.subtract(Duration(days: 1));
}
return getDateTimeDayStart(time);
}