mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-23 22:25:09 -04:00
Auto detect first day of week for calendar
New: Calendar will use systems first day of week when displaying
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user