1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 03:45:41 +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) public static DateTime Last(this DateTime current, DayOfWeek dayOfWeek)
{ {
DateTime last = current.LastDayOfMonth(); DateTime last = current.LastDayOfMonth();
DayOfWeek lastDayOfWeek = last.DayOfWeek;
last = last.AddDays(Math.Abs(dayOfWeek - last.DayOfWeek) * -1); int diff = -Math.Abs(dayOfWeek - lastDayOfWeek);
return last; return last.AddDays(diff);
} }
/// <summary> /// <summary>
@ -78,7 +79,7 @@
/// <param name="current">The current date.</param> /// <param name="current">The current date.</param>
public static DateTime Midnight(this DateTime current) 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> /// <summary>