1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 00:25:40 +00:00

🔨 Reduce code complexity in DateTime.Last

This commit is contained in:
Oliver Booth 2019-12-17 11:51:24 +00:00
parent d2208f2f6a
commit d246abd397
No known key found for this signature in database
GPG Key ID: 0D7F2EF1C8D2B9C0

View File

@ -67,9 +67,10 @@
public static DateTime Last(this DateTime current, DayOfWeek dayOfWeek)
{
DateTime last = current.LastDayOfMonth();
DayOfWeek lastDayOfWeek = last.DayOfWeek;
last = last.AddDays(Math.Abs(dayOfWeek - last.DayOfWeek) * -1);
return last;
int diff = -Math.Abs(dayOfWeek - lastDayOfWeek);
return last.AddDays(diff);
}
/// <summary>
@ -78,7 +79,7 @@
/// <param name="current">The current date.</param>
public static DateTime Midnight(this DateTime current)
{
return new DateTime(current.Year, current.Month, current.Day);
return new DateTime(current.Year, current.Month, current.Day, 0, 0, 0);
}
/// <summary>