mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-17 11:43:44 +01:00
fixes #552 - Add parental control usage limits
This commit is contained in:
@@ -6,6 +6,7 @@ using MediaBrowser.Model.Connect;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -259,5 +260,41 @@ namespace MediaBrowser.Controller.Entities
|
||||
Configuration = config;
|
||||
UserManager.UpdateConfiguration(this, Configuration);
|
||||
}
|
||||
|
||||
public bool IsParentalScheduleAllowed()
|
||||
{
|
||||
return IsParentalScheduleAllowed(DateTime.UtcNow);
|
||||
}
|
||||
|
||||
public bool IsParentalScheduleAllowed(DateTime date)
|
||||
{
|
||||
var schedules = Configuration.AccessSchedules;
|
||||
|
||||
if (schedules.Length == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return schedules.Any(i => IsParentalScheduleAllowed(i, date));
|
||||
}
|
||||
|
||||
private bool IsParentalScheduleAllowed(AccessSchedule schedule, DateTime date)
|
||||
{
|
||||
if (date.Kind != DateTimeKind.Utc)
|
||||
{
|
||||
throw new ArgumentException("Utc date expected");
|
||||
}
|
||||
|
||||
var localTime = date.ToLocalTime();
|
||||
|
||||
return localTime.DayOfWeek == schedule.DayOfWeek && IsWithinTime(schedule, localTime);
|
||||
}
|
||||
|
||||
private bool IsWithinTime(AccessSchedule schedule, DateTime localTime)
|
||||
{
|
||||
var hour = localTime.TimeOfDay.TotalHours;
|
||||
|
||||
return hour >= schedule.StartHour && hour <= schedule.EndHour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user