diff --git a/Jellyfin/backend/Api/AccessWindowController.cs b/Jellyfin/backend/Api/AccessWindowController.cs
new file mode 100644
index 00000000..62f304af
--- /dev/null
+++ b/Jellyfin/backend/Api/AccessWindowController.cs
@@ -0,0 +1,312 @@
+using System.Collections;
+using System.Net.Mime;
+using System.Text.Json.Serialization;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Moonfin.Server.Helpers;
+
+namespace Moonfin.Server.Api;
+
+///
+/// Whether the signed in user's access schedule lets them in right now, and how long until that
+/// changes. Jellyfin judges the schedule against the server's local time, so a client in another
+/// time zone can't work this out itself; this answers it with the same rule Jellyfin enforces,
+/// as relative durations a client can set a timer from without knowing the server's clock.
+///
+[ApiController]
+[Route("Moonfin")]
+[Produces(MediaTypeNames.Application.Json)]
+public class AccessWindowController : ControllerBase
+{
+ private readonly IServiceProvider _services;
+
+ public AccessWindowController(IServiceProvider services)
+ {
+ _services = services;
+ }
+
+ /// The user's access window: allowed now, and seconds until it closes or next opens.
+ ///
+ /// Skips the access-schedule check: a user outside their hours is exactly the one whose client
+ /// needs to know when the account next opens.
+ ///
+ [HttpGet("AccessWindow")]
+ [Authorize(Policy = "IgnoreParentalControl")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status400BadRequest)]
+ [ProducesResponseType(StatusCodes.Status401Unauthorized)]
+ [ProducesResponseType(StatusCodes.Status501NotImplemented)]
+ public ActionResult GetAccessWindow()
+ {
+ // Jellyfin doesn't hold administrators to a schedule
+ if (this.IsAdminFromClaims())
+ {
+ return Ok(new AccessWindowResponse { Allowed = true });
+ }
+
+ var userId = this.GetUserIdFromClaims();
+ if (userId is not { } id || id == Guid.Empty)
+ {
+ return BadRequest();
+ }
+
+ var user = UserReflection.ResolveUser(_services, id);
+ var entries = user == null ? null : ReadSchedule(user);
+ if (entries == null)
+ {
+ // Not Implemented, like a plugin without the endpoint, so clients judge it themselves
+ return Problem("The user's access schedule couldn't be read on this server version.", statusCode: StatusCodes.Status501NotImplemented);
+ }
+
+ return Ok(Evaluate(entries, DateTimeOffset.UtcNow, TimeZoneInfo.Local));
+ }
+
+ ///
+ /// The user's access schedule entries, read by name because Jellyfin's User and AccessSchedule
+ /// types moved between 10.10 and 10.11. Null when they can't be read.
+ ///
+ internal static List? ReadSchedule(object user)
+ {
+ try
+ {
+ if (user.GetType().GetProperty("AccessSchedules")?.GetValue(user) is not IEnumerable schedules)
+ {
+ return null;
+ }
+
+ var entries = new List();
+ foreach (var schedule in schedules)
+ {
+ var type = schedule.GetType();
+ var day = type.GetProperty("DayOfWeek")?.GetValue(schedule)?.ToString();
+ var start = type.GetProperty("StartHour")?.GetValue(schedule);
+ var end = type.GetProperty("EndHour")?.GetValue(schedule);
+ if (day == null || start == null || end == null)
+ {
+ return null;
+ }
+
+ entries.Add(new ScheduleEntry(day, Convert.ToDouble(start), Convert.ToDouble(end)));
+ }
+
+ return entries;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ // Long enough to find any change. The schedule repeats every week, but a daylight saving change can
+ // skip one week's window entirely (Sunday 02:30-02:45 never happens on New York's spring-forward
+ // night), and no two such changes come in consecutive weeks. So the next change is at most two
+ // weeks and an hour away, and nothing changes ever if nothing changes in that time.
+ internal static readonly TimeSpan DefaultLookAhead = TimeSpan.FromDays(15);
+
+ ///
+ /// The access window at for a server in : allowed
+ /// when there are no entries or falls in one of the schedule's periods,
+ /// with the time until that period ends or the next one starts. The time is left out unless it
+ /// comes before the end of , which must be positive.
+ ///
+ internal static AccessWindowResponse Evaluate(IReadOnlyList entries, DateTimeOffset now, TimeZoneInfo zone, TimeSpan? lookAhead = null)
+ {
+ if (entries.Count == 0)
+ {
+ return new AccessWindowResponse { Allowed = true };
+ }
+
+ var span = lookAhead ?? DefaultLookAhead;
+ ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(span, TimeSpan.Zero, nameof(lookAhead));
+ now = now.ToUniversalTime();
+ var limit = now + span;
+ var periods = BuildPeriods(entries, now, limit, zone);
+ var current = periods.Find(p => p.Start <= now && now < p.End);
+ var allowed = current != default;
+ var change = allowed ? current.End : periods.Find(p => p.Start > now).Start;
+
+ var response = new AccessWindowResponse { Allowed = allowed };
+ // A period cut off at the limit doesn't end there, and no next period means no opening
+ if (change > now && change < limit)
+ {
+ // Rounded up, so a timer set from it never fires before the change
+ var seconds = (long)Math.Ceiling((change - now).TotalSeconds);
+ if (allowed)
+ {
+ response.SecondsUntilClose = seconds;
+ }
+ else
+ {
+ response.SecondsUntilOpen = seconds;
+ }
+ }
+
+ return response;
+ }
+
+ ///
+ /// The schedule as UTC periods between and for a
+ /// server in , sorted, and merged where they overlap or touch, judged the
+ /// way Jellyfin judges it (UserEntityExtensions.IsParentalScheduleAllowed): an entry lets the
+ /// user in on its days while the server's local hour is between its start and end, both
+ /// included. While the zone's UTC offset holds, the local time is UTC plus that offset, so each
+ /// entry's hours are shifted by the offset and cut to that stretch. That way an hour skipped by
+ /// daylight saving drops out and a repeated one counts twice.
+ ///
+ internal static List BuildPeriods(IReadOnlyList entries, DateTimeOffset from, DateTimeOffset to, TimeZoneInfo zone)
+ {
+ var periods = new List();
+ foreach (var (start, end, offset) in OffsetStretches(from.ToUniversalTime(), to.ToUniversalTime(), zone))
+ {
+ for (var day = (start + offset).Date; day <= (end + offset).Date; day = day.AddDays(1))
+ {
+ foreach (var entry in entries.Where(e => e.Covers(day.DayOfWeek)))
+ {
+ // Jellyfin's comparisons with a NaN hour are always false, so the entry never lets them in
+ if (double.IsNaN(entry.StartHour) || double.IsNaN(entry.EndHour))
+ {
+ continue;
+ }
+
+ // Jellyfin compares the local hour of the day, 0 up to 24, with the hours as stored,
+ // so an end past 24 lasts to midnight and a start below 0 is midnight
+ var open = FirstTick(entry.StartHour, hour => hour >= entry.StartHour);
+ var close = FirstTick(entry.EndHour, hour => hour > entry.EndHour);
+ var midnight = day.Ticks - offset.Ticks;
+ var period = new AccessPeriod(
+ Later(start, new DateTimeOffset(midnight + open, TimeSpan.Zero)),
+ Earlier(end, new DateTimeOffset(midnight + close, TimeSpan.Zero)));
+ if (period.Start < period.End)
+ {
+ periods.Add(period);
+ }
+ }
+ }
+ }
+
+ periods.Sort((a, b) => a.Start.CompareTo(b.Start));
+ var merged = new List();
+ foreach (var period in periods)
+ {
+ if (merged.Count > 0 && period.Start <= merged[^1].End)
+ {
+ merged[^1] = merged[^1] with { End = Later(merged[^1].End, period.End) };
+ }
+ else
+ {
+ merged.Add(period);
+ }
+ }
+
+ return merged;
+ }
+
+ // Clock changes are never closer together than this. The closest in today's rules are Morocco's
+ // around Ramadan, about five weeks apart; two weeks leaves room for a rule changed at short notice.
+ private static readonly TimeSpan OffsetChangeSpacing = TimeSpan.FromDays(14);
+
+ ///
+ /// Splits the time from to into stretches with one UTC
+ /// offset each, cut wherever the server's clock goes forward or back.
+ ///
+ ///
+ /// .NET can't tell us when the next clock change is, so this searches for it. It steps through the
+ /// time in pieces of . A piece that short holds one change at most,
+ /// so if the offset at its end differs from its start there is exactly one change in it, and a
+ /// binary search finds the tick it happens at.
+ ///
+ private static IEnumerable<(DateTimeOffset Start, DateTimeOffset End, TimeSpan Offset)> OffsetStretches(DateTimeOffset from, DateTimeOffset to, TimeZoneInfo zone)
+ {
+ var start = from;
+ var offset = zone.GetUtcOffset(from);
+ for (var piece = from; piece < to; piece += OffsetChangeSpacing)
+ {
+ var low = piece;
+ var high = Earlier(piece + OffsetChangeSpacing, to);
+ if (zone.GetUtcOffset(high) == offset)
+ {
+ // Same offset at both ends: no change in this piece
+ continue;
+ }
+
+ // Narrow down to the first tick with the new offset
+ while (high.UtcTicks - low.UtcTicks > 1)
+ {
+ var middle = low.AddTicks((high.UtcTicks - low.UtcTicks) / 2);
+ (low, high) = zone.GetUtcOffset(middle) == offset ? (middle, high) : (low, middle);
+ }
+
+ yield return (start, high, offset);
+ start = high;
+ offset = zone.GetUtcOffset(high);
+ }
+
+ yield return (start, to, offset);
+ }
+
+ ///
+ /// The first tick of the day at which the hour as Jellyfin reads it (TimeOfDay.TotalHours) passes
+ /// , or the day's end when none does. The estimate from
+ /// can be a tick out from rounding (an end of 8.04 still lets the user in
+ /// at 08:02:24 exactly), so it's moved a tick at a time to where the comparison turns.
+ ///
+ private static long FirstTick(double hours, Func passes)
+ {
+ var tick = (long)Math.Clamp(Math.Ceiling(hours * TimeSpan.TicksPerHour), 0, TimeSpan.TicksPerDay);
+ while (tick > 0 && passes(TimeSpan.FromTicks(tick - 1).TotalHours))
+ {
+ tick--;
+ }
+
+ while (tick < TimeSpan.TicksPerDay && !passes(TimeSpan.FromTicks(tick).TotalHours))
+ {
+ tick++;
+ }
+
+ return tick;
+ }
+
+ private static DateTimeOffset Earlier(DateTimeOffset a, DateTimeOffset b) => a < b ? a : b;
+
+ private static DateTimeOffset Later(DateTimeOffset a, DateTimeOffset b) => a > b ? a : b;
+}
+
+/// A time in which the schedule lets the user in, from Start up to but not including End.
+internal readonly record struct AccessPeriod(DateTimeOffset Start, DateTimeOffset End);
+
+/// One access schedule entry: a day name as Jellyfin's DynamicDayOfWeek writes it, and the hours.
+internal readonly record struct ScheduleEntry(string Day, double StartHour, double EndHour)
+{
+ /// Jellyfin's DayOfWeekHelper.Contains.
+ public bool Covers(DayOfWeek day) => Day switch
+ {
+ "Everyday" => true,
+ "Weekday" => day is >= DayOfWeek.Monday and <= DayOfWeek.Friday,
+ "Weekend" => day is DayOfWeek.Saturday or DayOfWeek.Sunday,
+ _ => Enum.TryParse(Day, out var named) && named == day,
+ };
+}
+
+public class AccessWindowResponse
+{
+ /// True when the user's schedule lets them in now. Always true for an administrator or a user with no schedule.
+ [JsonPropertyName("allowed")]
+ public bool Allowed { get; set; }
+
+ ///
+ /// When allowed, seconds until the schedule closes, rounded up. Left out when allowed with no
+ /// schedule, or when it doesn't close within two weeks (open all week).
+ ///
+ [JsonPropertyName("secondsUntilClose")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public long? SecondsUntilClose { get; set; }
+
+ ///
+ /// When not allowed, seconds until the schedule next opens, rounded up. Left out when it
+ /// doesn't open within two weeks (an entry that never opens).
+ ///
+ [JsonPropertyName("secondsUntilOpen")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public long? SecondsUntilOpen { get; set; }
+}
diff --git a/Jellyfin/tests/Moonfin.Server.Tests/AccessWindowTests.cs b/Jellyfin/tests/Moonfin.Server.Tests/AccessWindowTests.cs
new file mode 100644
index 00000000..7ed3f2ed
--- /dev/null
+++ b/Jellyfin/tests/Moonfin.Server.Tests/AccessWindowTests.cs
@@ -0,0 +1,522 @@
+using System.Reflection;
+using System.Text.Json;
+using Microsoft.AspNetCore.Authorization;
+using Moonfin.Server.Api;
+using Xunit;
+
+namespace Moonfin.Server.Tests;
+
+public sealed class AccessWindowTests
+{
+ private static readonly TimeZoneInfo Utc = TimeZoneInfo.Utc;
+
+ private static TimeZoneInfo Fixed(string offset) =>
+ TimeZoneInfo.CreateCustomTimeZone("Test/Zone", TimeSpan.Parse(offset), "Test", "Test");
+
+ // Null on a host with no tz database, where the test is skipped quietly
+ private static TimeZoneInfo? Named(string id)
+ {
+ try
+ {
+ return TimeZoneInfo.FindSystemTimeZoneById(id);
+ }
+ catch (TimeZoneNotFoundException)
+ {
+ return null;
+ }
+ }
+
+ private static ScheduleEntry Entry(string day, double start, double end) => new(day, start, end);
+
+ private static DateTimeOffset At(int year, int month, int day, int hour, int minute = 0) =>
+ new(year, month, day, hour, minute, 0, TimeSpan.Zero);
+
+ [Fact]
+ public void NoSchedule_IsAllowedWithNoClosing()
+ {
+ var window = AccessWindowController.Evaluate([], At(2026, 11, 16, 12), Utc);
+
+ Assert.True(window.Allowed);
+ Assert.Null(window.SecondsUntilClose);
+ Assert.Null(window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void EveryHourOfEveryDay_NeverCloses()
+ {
+ var window = AccessWindowController.Evaluate([Entry("Everyday", 0, 24)], At(2026, 11, 16, 12), Utc);
+
+ Assert.True(window.Allowed);
+ Assert.Null(window.SecondsUntilClose);
+ }
+
+ [Fact]
+ public void Allowed_ClosesTheSecondAfterTheEndHour()
+ {
+ // Monday 2026-11-16 19:00; Jellyfin still allows 20:00:00 itself
+ var window = AccessWindowController.Evaluate([Entry("Weekday", 8, 20)], At(2026, 11, 16, 19), Utc);
+
+ Assert.True(window.Allowed);
+ Assert.Equal(3601, window.SecondsUntilClose);
+ Assert.Null(window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void Blocked_OpensAtTheStartHour()
+ {
+ // Monday 21:00, next opening Tuesday 08:00
+ var window = AccessWindowController.Evaluate([Entry("Weekday", 8, 20)], At(2026, 11, 16, 21), Utc);
+
+ Assert.False(window.Allowed);
+ Assert.Equal(11 * 3600, window.SecondsUntilOpen);
+ Assert.Null(window.SecondsUntilClose);
+ }
+
+ [Fact]
+ public void Blocked_OverTheWeekendOpensMonday()
+ {
+ // Friday 2026-11-20 21:00 to Monday 08:00
+ var window = AccessWindowController.Evaluate([Entry("Weekday", 8, 20)], At(2026, 11, 20, 21), Utc);
+
+ Assert.Equal((3 + 2 * 24 + 8) * 3600, window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void AdjacentEntries_RunTogether()
+ {
+ // Monday 20:00-24:00 then Tuesday 00:00-08:00 is one spell, closing after Tuesday 08:00
+ var entries = new[] { Entry("Monday", 20, 24), Entry("Tuesday", 0, 8) };
+ var window = AccessWindowController.Evaluate(entries, At(2026, 11, 16, 21), Utc);
+
+ Assert.True(window.Allowed);
+ Assert.Equal(11 * 3600 + 1, window.SecondsUntilClose);
+ }
+
+ [Fact]
+ public void HalfHours_AreHonoured()
+ {
+ var window = AccessWindowController.Evaluate([Entry("Everyday", 7.5, 21.5)], At(2026, 11, 16, 6), Utc);
+
+ Assert.False(window.Allowed);
+ Assert.Equal(5400, window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void JudgedOnTheServersZone()
+ {
+ // 19:00Z is 00:30 Tuesday in India: closed for a Monday-only schedule, open for Tuesday
+ var india = Fixed("05:30");
+ Assert.False(AccessWindowController.Evaluate([Entry("Monday", 0, 24)], At(2026, 11, 16, 19), india).Allowed);
+ Assert.True(AccessWindowController.Evaluate([Entry("Tuesday", 0, 1)], At(2026, 11, 16, 19), india).Allowed);
+ }
+
+ [Fact]
+ public void AnEntryThatNeverOpens_GivesNoOpening()
+ {
+ var window = AccessWindowController.Evaluate([Entry("Everyday", 20, 8)], At(2026, 11, 16, 12), Utc);
+
+ Assert.False(window.Allowed);
+ Assert.Null(window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void AnEndPastMidnight_ClosesAtMidnight()
+ {
+ // Jellyfin stores hours as given; Monday 08:00-25:00 ends when Monday does
+ var window = AccessWindowController.Evaluate([Entry("Monday", 8, 25)], At(2026, 11, 16, 19), Utc);
+
+ Assert.True(window.Allowed);
+ Assert.Equal(5 * 3600, window.SecondsUntilClose);
+ }
+
+ [Fact]
+ public void AStartBeforeMidnight_OpensAtMidnight()
+ {
+ var window = AccessWindowController.Evaluate([Entry("Tuesday", -2, 6)], At(2026, 11, 16, 19), Utc);
+
+ Assert.False(window.Allowed);
+ Assert.Equal(5 * 3600, window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void FallBack_CountsTheRepeatedHour()
+ {
+ var newYork = Named("America/New_York");
+ if (newYork == null)
+ {
+ return;
+ }
+
+ // Sunday 2026-11-01 00:30 EDT (04:30Z); 03:00 EST is 08:00Z, three and a half hours on
+ var window = AccessWindowController.Evaluate([Entry("Sunday", 3, 12)], At(2026, 11, 1, 4, 30), newYork);
+
+ Assert.False(window.Allowed);
+ Assert.Equal(12600, window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void SpringForward_OpensWhenTheClockJumpsIntoTheWindow()
+ {
+ var newYork = Named("America/New_York");
+ if (newYork == null)
+ {
+ return;
+ }
+
+ // Sunday 2026-03-08 01:00 EST (06:00Z). 02:30 never happens; at 07:00Z the clock jumps
+ // from 02:00 EST to 03:00 EDT, inside 02:30-04:00
+ var window = AccessWindowController.Evaluate([Entry("Sunday", 2.5, 4)], At(2026, 3, 8, 6), newYork);
+
+ Assert.False(window.Allowed);
+ Assert.Equal(3600, window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void FallBack_SplitsAPeriodEndingInTheRepeatedHour()
+ {
+ var newYork = Named("America/New_York");
+ if (newYork == null)
+ {
+ return;
+ }
+
+ // Sunday 2026-11-01 00:00-01:30: 04:00Z-05:30Z on EDT, then the clock goes back to 01:00 EST
+ // at 06:00Z and reads 01:00-01:30 again until 06:30Z
+ var periods = AccessWindowController.BuildPeriods([Entry("Sunday", 0, 1.5)], At(2026, 11, 1, 0), At(2026, 11, 2, 0), newYork);
+
+ Assert.Equal(
+ [new AccessPeriod(At(2026, 11, 1, 4), At(2026, 11, 1, 5, 30).AddTicks(1)), new AccessPeriod(At(2026, 11, 1, 6), At(2026, 11, 1, 6, 30).AddTicks(1))],
+ periods);
+ }
+
+ [Fact]
+ public void BuildPeriods_CoversTheRangeAskedFor()
+ {
+ // Two weeks from Monday 2026-11-16: ten weekdays, the last cut off at the range's end
+ var periods = AccessWindowController.BuildPeriods([Entry("Weekday", 8, 20)], At(2026, 11, 16, 0), At(2026, 11, 27, 12), Utc);
+
+ Assert.Equal(10, periods.Count);
+ Assert.Equal(new AccessPeriod(At(2026, 11, 16, 8), At(2026, 11, 16, 20).AddTicks(1)), periods[0]);
+ Assert.Equal(new AccessPeriod(At(2026, 11, 27, 8), At(2026, 11, 27, 12)), periods[^1]);
+ }
+
+ [Fact]
+ public void BuildPeriods_FindsBothChangesInAYear()
+ {
+ var newYork = Named("America/New_York");
+ if (newYork == null)
+ {
+ return;
+ }
+
+ // All of 2026, EST at both ends; Sundays 02:30-04:00 local
+ var periods = AccessWindowController.BuildPeriods([Entry("Sunday", 2.5, 4)], At(2026, 1, 1, 0), At(2027, 1, 1, 0), newYork);
+
+ Assert.Equal(52, periods.Count);
+ // EST: 07:30Z-09:00Z
+ Assert.Contains(new AccessPeriod(At(2026, 3, 1, 7, 30), At(2026, 3, 1, 9).AddTicks(1)), periods);
+ // Spring forward: 02:30 never comes, the clock jumps to 03:00 EDT at 07:00Z
+ Assert.Contains(new AccessPeriod(At(2026, 3, 8, 7), At(2026, 3, 8, 8).AddTicks(1)), periods);
+ // EDT: 06:30Z-08:00Z
+ Assert.Contains(new AccessPeriod(At(2026, 7, 5, 6, 30), At(2026, 7, 5, 8).AddTicks(1)), periods);
+ // Fall back at 06:00Z: 02:30-04:00 EST
+ Assert.Contains(new AccessPeriod(At(2026, 11, 1, 7, 30), At(2026, 11, 1, 9).AddTicks(1)), periods);
+ }
+
+ [Fact]
+ public void SpringForward_SkippedWindow_NamesTheOneAfter()
+ {
+ var newYork = Named("America/New_York");
+ if (newYork == null)
+ {
+ return;
+ }
+
+ // Sunday 02:30-02:45 never happens on 2026-03-08. Just after the 2026-03-01 window (02:46 EST,
+ // 07:46Z) the next opening is 2026-03-15 02:30 EDT (06:30Z), 13 days 22:44 on
+ var window = AccessWindowController.Evaluate([Entry("Sunday", 2.5, 2.75)], At(2026, 3, 1, 7, 46), newYork);
+
+ Assert.False(window.Allowed);
+ Assert.Equal(1205040, window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void AFractionalEnd_ClosesAtJellyfinsTick()
+ {
+ // Jellyfin still lets the user in at 08:02:24 exactly for an end of 8.04, where the hours times
+ // the ticks in an hour rounds to just below that tick
+ var monday = At(2026, 11, 16, 0);
+ var periods = AccessWindowController.BuildPeriods([Entry("Monday", 8, 8.04)], monday, monday.AddDays(1), Utc);
+
+ Assert.Equal(new AccessPeriod(At(2026, 11, 16, 8), At(2026, 11, 16, 8, 2).AddSeconds(24).AddTicks(1)), Assert.Single(periods));
+ Assert.Equal(2, AccessWindowController.Evaluate([Entry("Monday", 8, 8.04)], At(2026, 11, 16, 8, 2).AddSeconds(23), Utc).SecondsUntilClose);
+ }
+
+ [Fact]
+ public void AbsurdHours_AreSkippedWithoutBreakingTheRest()
+ {
+ // Jellyfin stores the hours as given; these never let the user in, and mustn't stop the valid entry
+ var entries = new[]
+ {
+ Entry("Monday", 8, -100_000_000), Entry("Monday", 100_000_000, 200_000_000),
+ Entry("Monday", double.NaN, 12), Entry("Monday", 8, double.NaN), Entry("Monday", 9, 17),
+ };
+ var window = AccessWindowController.Evaluate(entries, At(2026, 11, 16, 12), Utc);
+
+ Assert.True(window.Allowed);
+ // The end hour is included, so it closes a tick after 17:00, rounded up to the next second
+ Assert.Equal(5 * 3600 + 1, window.SecondsUntilClose);
+ }
+
+ [Fact]
+ public void LookAhead_MustBePositive()
+ {
+ Assert.Throws(() => AccessWindowController.Evaluate([Entry("Weekday", 8, 20)], At(2026, 11, 16, 12), Utc, TimeSpan.Zero));
+ }
+
+ [Fact]
+ public void LookAhead_LeavesOutChangesBeyondIt()
+ {
+ // Friday 21:00, opens Monday 08:00: 59 hours on, past a two-day look-ahead
+ var window = AccessWindowController.Evaluate([Entry("Weekday", 8, 20)], At(2026, 11, 20, 21), Utc, TimeSpan.FromDays(2));
+
+ Assert.False(window.Allowed);
+ Assert.Null(window.SecondsUntilOpen);
+ }
+
+ [Fact]
+ public void LookAhead_LeavesOutAChangeExactlyAtItsEnd()
+ {
+ // Friday 21:00, opens Monday 08:00, exactly 59 hours on: left out at 59 hours, given a tick later
+ var friday = At(2026, 11, 20, 21);
+ var entries = new[] { Entry("Weekday", 8, 20) };
+
+ Assert.Null(AccessWindowController.Evaluate(entries, friday, Utc, TimeSpan.FromHours(59)).SecondsUntilOpen);
+ Assert.Equal(59 * 3600, AccessWindowController.Evaluate(entries, friday, Utc, TimeSpan.FromHours(59).Add(TimeSpan.FromTicks(1))).SecondsUntilOpen);
+ }
+
+ public static IEnumerable