Auto detect first day of week for calendar

New: Calendar will use systems first day of week when displaying
pull/3113/head
Mark McDowall 11 years ago
parent 76089b460c
commit fe5b42696d

@ -42,7 +42,8 @@ namespace NzbDrone.Api.System
IsLinux = OsInfo.IsLinux, IsLinux = OsInfo.IsLinux,
IsWindows = OsInfo.IsWindows, IsWindows = OsInfo.IsWindows,
Branch = _configFileProvider.Branch, Branch = _configFileProvider.Branch,
Authentication = _configFileProvider.AuthenticationEnabled Authentication = _configFileProvider.AuthenticationEnabled,
StartOfWeek = (int)OsInfo.FirstDayOfWeek
}.AsResponse(); }.AsResponse();
} }

@ -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;
}
}
}

@ -28,5 +28,13 @@ namespace NzbDrone.Common.EnvironmentInfo
return !IsLinux; return !IsLinux;
} }
} }
public static DayOfWeek FirstDayOfWeek
{
get
{
return DateTime.Today.GetFirstDayOfWeek().DayOfWeek;
}
}
} }
} }

@ -66,6 +66,7 @@
<Compile Include="Composition\Container.cs" /> <Compile Include="Composition\Container.cs" />
<Compile Include="Composition\IContainer.cs" /> <Compile Include="Composition\IContainer.cs" />
<Compile Include="Composition\ContainerBuilderBase.cs" /> <Compile Include="Composition\ContainerBuilderBase.cs" />
<Compile Include="DateTimeExtensions.cs" />
<Compile Include="EnsureThat\Ensure.cs" /> <Compile Include="EnsureThat\Ensure.cs" />
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" /> <Compile Include="EnsureThat\EnsureBoolExtensions.cs" />
<Compile Include="EnsureThat\EnsureCollectionExtensions.cs" /> <Compile Include="EnsureThat\EnsureCollectionExtensions.cs" />

@ -21,6 +21,7 @@ define(
allDayDefault : false, allDayDefault : false,
ignoreTimezone: false, ignoreTimezone: false,
weekMode : 'variable', weekMode : 'variable',
firstDay : window.NzbDrone.ServerStatus.startOfWeek,
timeFormat : 'h(:mm)tt', timeFormat : 'h(:mm)tt',
header : { header : {
left : 'prev,next today', left : 'prev,next today',

Loading…
Cancel
Save