1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-18 23:48:35 +02:00
Sonarr/NzbDrone.Common/DateTimeExtensions.cs
Mark McDowall fe5b42696d Auto detect first day of week for calendar
New: Calendar will use systems first day of week when displaying
2013-10-02 12:41:21 -07:00

25 lines
763 B
C#

using System;
using System.Globalization;
namespace NzbDrone.Common
{
public static class DateTimeExtensions
{
public static DateTime GetFirstDayOfWeek(this DateTime dayInWeek)
{
var defaultCultureInfo = CultureInfo.CurrentCulture;
return GetFirstDayOfWeek(dayInWeek, defaultCultureInfo);
}
public static DateTime GetFirstDayOfWeek(this DateTime dayInWeek, CultureInfo cultureInfo)
{
DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek;
DateTime firstDayInWeek = dayInWeek.Date;
while (firstDayInWeek.DayOfWeek != firstDay)
firstDayInWeek = firstDayInWeek.AddDays(-1);
return firstDayInWeek;
}
}
}