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:
parent
d2208f2f6a
commit
d246abd397
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user