jellyfin/Jellyfin.Data/DayOfWeekHelper.cs

33 lines
1.3 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System;
2020-05-13 04:10:35 +02:00
using Jellyfin.Data.Enums;
2018-12-28 00:27:57 +01:00
2020-05-13 04:10:35 +02:00
namespace Jellyfin.Data
2018-12-28 00:27:57 +01:00
{
public static class DayOfWeekHelper
{
2021-03-09 05:57:38 +01:00
public static DayOfWeek[] GetDaysOfWeek(DynamicDayOfWeek day)
2018-12-28 00:27:57 +01:00
{
2021-03-09 05:57:38 +01:00
return day switch
2018-12-28 00:27:57 +01:00
{
2021-03-13 22:40:23 +01:00
DynamicDayOfWeek.Everyday => new[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday },
2021-03-09 17:01:14 +01:00
DynamicDayOfWeek.Weekday => new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday },
DynamicDayOfWeek.Weekend => new[] { DayOfWeek.Sunday, DayOfWeek.Saturday },
2021-03-09 05:57:38 +01:00
_ => new[] { (DayOfWeek)day }
};
2018-12-28 00:27:57 +01:00
}
2023-02-08 23:55:26 +01:00
public static bool Contains(this DynamicDayOfWeek dynamicDayOfWeek, DayOfWeek dayOfWeek)
{
return dynamicDayOfWeek switch
{
DynamicDayOfWeek.Everyday => true,
DynamicDayOfWeek.Weekday => dayOfWeek is >= DayOfWeek.Monday and <= DayOfWeek.Friday,
2023-02-08 23:55:26 +01:00
DynamicDayOfWeek.Weekend => dayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday,
_ => (DayOfWeek)dynamicDayOfWeek == dayOfWeek
};
}
2018-12-28 00:27:57 +01:00
}
}