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