From e4ff825ae8a637d0449b9e38fa9522a3f6e18c1a Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:11:57 -0600 Subject: [PATCH] fix displaying playout item durations that are greater than 24 hours (#1932) * fix displaying playout item durations that are greater than 24 hours * upgrade refit to make build happy * upgrade all dependencies --- CHANGELOG.md | 1 + .../ErsatzTV.Application.csproj | 2 +- ErsatzTV.Application/Playouts/Mapper.cs | 8 +--- ErsatzTV.Application/Scheduling/Mapper.cs | 2 +- .../Domain/PlayoutItemTests.cs | 37 +++++++++++++++++++ .../ErsatzTV.Core.Tests.csproj | 8 ++-- .../Fakes/FakeTelevisionRepository.cs | 2 +- ErsatzTV.Core/Domain/PlayoutItem.cs | 17 +++++++++ ErsatzTV.Core/ErsatzTV.Core.csproj | 6 +-- .../ErsatzTV.FFmpeg.Tests.csproj | 4 +- ErsatzTV.FFmpeg/ErsatzTV.FFmpeg.csproj | 2 +- .../ErsatzTV.Infrastructure.Tests.csproj | 4 +- .../ErsatzTV.Infrastructure.csproj | 18 ++++----- .../ErsatzTV.Scanner.Tests.csproj | 4 +- ErsatzTV.Scanner/ErsatzTV.Scanner.csproj | 4 +- ErsatzTV/ErsatzTV.csproj | 8 ++-- 16 files changed, 88 insertions(+), 39 deletions(-) create mode 100644 ErsatzTV.Core.Tests/Domain/PlayoutItemTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 333a3855..a0577df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix deleting local libraries with MySql backend - Fix `Scaling Behavior` `Crop` when content is smaller than FFmpeg Profile resolution - Now, content will properly scale beyond the desired resolution before cropping +- Fix displaying playout item durations that are greater than 24 hours ## [0.8.8-beta] - 2024-09-19 ### Added diff --git a/ErsatzTV.Application/ErsatzTV.Application.csproj b/ErsatzTV.Application/ErsatzTV.Application.csproj index 4004b4a0..9121cd96 100644 --- a/ErsatzTV.Application/ErsatzTV.Application.csproj +++ b/ErsatzTV.Application/ErsatzTV.Application.csproj @@ -10,7 +10,7 @@ - + diff --git a/ErsatzTV.Application/Playouts/Mapper.cs b/ErsatzTV.Application/Playouts/Mapper.cs index 74f32daf..d078fe3a 100644 --- a/ErsatzTV.Application/Playouts/Mapper.cs +++ b/ErsatzTV.Application/Playouts/Mapper.cs @@ -10,7 +10,7 @@ internal static class Mapper GetDisplayTitle(playoutItem), playoutItem.StartOffset, playoutItem.FinishOffset, - GetDisplayDuration(playoutItem.FinishOffset - playoutItem.StartOffset)); + playoutItem.GetDisplayDuration()); internal static PlayoutAlternateScheduleViewModel ProjectToViewModel( ProgramScheduleAlternate programScheduleAlternate) => @@ -81,10 +81,4 @@ internal static class Mapper return string.Empty; } } - - internal static string GetDisplayDuration(TimeSpan duration) => - string.Format( - CultureInfo.InvariantCulture, - duration.TotalHours >= 1 ? @"{0:h\:mm\:ss}" : @"{0:mm\:ss}", - duration); } diff --git a/ErsatzTV.Application/Scheduling/Mapper.cs b/ErsatzTV.Application/Scheduling/Mapper.cs index e746c3d6..b3f30411 100644 --- a/ErsatzTV.Application/Scheduling/Mapper.cs +++ b/ErsatzTV.Application/Scheduling/Mapper.cs @@ -116,5 +116,5 @@ internal static class Mapper Playouts.Mapper.GetDisplayTitle(playoutItem), playoutItem.StartOffset.TimeOfDay, playoutItem.FinishOffset.TimeOfDay, - Playouts.Mapper.GetDisplayDuration(playoutItem.FinishOffset - playoutItem.StartOffset)); + playoutItem.GetDisplayDuration()); } diff --git a/ErsatzTV.Core.Tests/Domain/PlayoutItemTests.cs b/ErsatzTV.Core.Tests/Domain/PlayoutItemTests.cs new file mode 100644 index 00000000..1d728957 --- /dev/null +++ b/ErsatzTV.Core.Tests/Domain/PlayoutItemTests.cs @@ -0,0 +1,37 @@ +using ErsatzTV.Core.Domain; +using FluentAssertions; +using NUnit.Framework; + +namespace ErsatzTV.Core.Tests.Domain; + +[TestFixture] +public class PlayoutItemTests +{ + [Test] + public void GetDisplayDuration_ShortDuration() + { + var item = new PlayoutItem + { + Start = DateTime.UtcNow.Date, + Finish = DateTime.UtcNow.Date.AddHours(3).AddMinutes(5).AddSeconds(4) + }; + + string actual = item.GetDisplayDuration(); + + actual.Should().Be("3:05:04"); + } + + [Test] + public void GetDisplayDuration_LongDuration() + { + var item = new PlayoutItem + { + Start = DateTime.UtcNow.Date, + Finish = DateTime.UtcNow.Date.AddHours(27).AddMinutes(5).AddSeconds(4) + }; + + string actual = item.GetDisplayDuration(); + + actual.Should().Be("27:05:04"); + } +} diff --git a/ErsatzTV.Core.Tests/ErsatzTV.Core.Tests.csproj b/ErsatzTV.Core.Tests/ErsatzTV.Core.Tests.csproj index 69509e44..a5112284 100644 --- a/ErsatzTV.Core.Tests/ErsatzTV.Core.Tests.csproj +++ b/ErsatzTV.Core.Tests/ErsatzTV.Core.Tests.csproj @@ -8,8 +8,8 @@ - - + + @@ -21,10 +21,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/ErsatzTV.Core.Tests/Fakes/FakeTelevisionRepository.cs b/ErsatzTV.Core.Tests/Fakes/FakeTelevisionRepository.cs index 72e2dd83..8f0e894d 100644 --- a/ErsatzTV.Core.Tests/Fakes/FakeTelevisionRepository.cs +++ b/ErsatzTV.Core.Tests/Fakes/FakeTelevisionRepository.cs @@ -65,7 +65,7 @@ public class FakeTelevisionRepository : ITelevisionRepository public Task AddGenre(ShowMetadata metadata, Genre genre) => throw new NotSupportedException(); public Task AddGenre(EpisodeMetadata metadata, Genre genre) => throw new NotSupportedException(); - public Task AddTag(Domain.Metadata metadata, Tag tag) => throw new NotSupportedException(); + public Task AddTag(ErsatzTV.Core.Domain.Metadata metadata, Tag tag) => throw new NotSupportedException(); public Task AddStudio(ShowMetadata metadata, Studio studio) => throw new NotSupportedException(); public Task AddActor(ShowMetadata metadata, Actor actor) => throw new NotSupportedException(); diff --git a/ErsatzTV.Core/Domain/PlayoutItem.cs b/ErsatzTV.Core/Domain/PlayoutItem.cs index f385e163..8d3ba1b4 100644 --- a/ErsatzTV.Core/Domain/PlayoutItem.cs +++ b/ErsatzTV.Core/Domain/PlayoutItem.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; using ErsatzTV.Core.Domain.Filler; namespace ErsatzTV.Core.Domain; @@ -55,4 +56,20 @@ public class PlayoutItem OutPoint = chapter.EndTime, ChapterTitle = chapter.Title }; + + public string GetDisplayDuration() + { + TimeSpan duration = FinishOffset - StartOffset; + + if (duration >= TimeSpan.FromHours(24)) + { + var ms = string.Format(CultureInfo.InvariantCulture, @"{0:mm\:ss}", duration); + return $"{(int)duration.TotalHours}:{ms}"; + } + + return string.Format( + CultureInfo.InvariantCulture, + duration.TotalHours >= 1 ? @"{0:h\:mm\:ss}" : @"{0:mm\:ss}", + duration); + } } diff --git a/ErsatzTV.Core/ErsatzTV.Core.csproj b/ErsatzTV.Core/ErsatzTV.Core.csproj index 51e2d215..91c7c126 100644 --- a/ErsatzTV.Core/ErsatzTV.Core.csproj +++ b/ErsatzTV.Core/ErsatzTV.Core.csproj @@ -25,10 +25,10 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + - - + + diff --git a/ErsatzTV.FFmpeg.Tests/ErsatzTV.FFmpeg.Tests.csproj b/ErsatzTV.FFmpeg.Tests/ErsatzTV.FFmpeg.Tests.csproj index a33ccced..f0ca8a96 100644 --- a/ErsatzTV.FFmpeg.Tests/ErsatzTV.FFmpeg.Tests.csproj +++ b/ErsatzTV.FFmpeg.Tests/ErsatzTV.FFmpeg.Tests.csproj @@ -8,10 +8,10 @@ - + - + diff --git a/ErsatzTV.FFmpeg/ErsatzTV.FFmpeg.csproj b/ErsatzTV.FFmpeg/ErsatzTV.FFmpeg.csproj index dc41ecfb..b40506a5 100644 --- a/ErsatzTV.FFmpeg/ErsatzTV.FFmpeg.csproj +++ b/ErsatzTV.FFmpeg/ErsatzTV.FFmpeg.csproj @@ -9,7 +9,7 @@ - + diff --git a/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj b/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj index ec5e0f67..24431ead 100644 --- a/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj +++ b/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj @@ -9,9 +9,9 @@ - + - + diff --git a/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj b/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj index 44fb320b..61085c8e 100644 --- a/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj +++ b/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj @@ -11,13 +11,13 @@ - + - - - - + + + + all @@ -28,10 +28,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj b/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj index c9435ad9..ff47741e 100644 --- a/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj +++ b/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj @@ -9,10 +9,10 @@ - + - + diff --git a/ErsatzTV.Scanner/ErsatzTV.Scanner.csproj b/ErsatzTV.Scanner/ErsatzTV.Scanner.csproj index 439de3ef..c444262b 100644 --- a/ErsatzTV.Scanner/ErsatzTV.Scanner.csproj +++ b/ErsatzTV.Scanner/ErsatzTV.Scanner.csproj @@ -20,14 +20,14 @@ - + - + diff --git a/ErsatzTV/ErsatzTV.csproj b/ErsatzTV/ErsatzTV.csproj index 27ef6f8b..6dd39a3e 100644 --- a/ErsatzTV/ErsatzTV.csproj +++ b/ErsatzTV/ErsatzTV.csproj @@ -23,7 +23,7 @@ - + @@ -37,10 +37,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - + +