diff --git a/Iceshrimp.Backend/Core/Extensions/NumberExtensions.cs b/Iceshrimp.Backend/Core/Extensions/NumberExtensions.cs index 8dae97b1..baa637fb 100644 --- a/Iceshrimp.Backend/Core/Extensions/NumberExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/NumberExtensions.cs @@ -33,4 +33,26 @@ public static class NumberExtensions return result.ToString(); } + + public static string ToDurationDisplayString(this long input) + { + return input switch + { + < 1000 => $"{input} ms", + < 1000 * 60 => $"{Math.Round(input / 1000d / 60d, 2)} s", + < 1000 * 60 * 60 => $"{Math.Round(input / 60000d / 60d, 2)} m", + _ => $"{Math.Round(input / 60000d / 60d / 60d, 2)} h" + }; + } + + public static string ToDurationDisplayString(this int input) + { + return input switch + { + < 1000 => $"{input} ms", + < 1000 * 60 => $"{Math.Round(input / 1000d / 60d, 2)} s", + < 1000 * 60 * 60 => $"{Math.Round(input / 60000d / 60d, 2)} m", + _ => $"{Math.Round(input / 60000d / 60d / 60d, 2)} h" + }; + } } \ No newline at end of file diff --git a/Iceshrimp.Backend/Pages/Queue.cshtml b/Iceshrimp.Backend/Pages/Queue.cshtml index cc894041..3446f383 100644 --- a/Iceshrimp.Backend/Pages/Queue.cshtml +++ b/Iceshrimp.Backend/Pages/Queue.cshtml @@ -127,9 +127,9 @@ else var id = job.Id.ToStringLower(); var additional = job.Status switch { - Job.JobStatus.Queued => $"for {job.QueueDuration} ms", + Job.JobStatus.Queued => $"for {job.QueueDuration.ToDurationDisplayString()}", + Job.JobStatus.Running => $"for {job.Duration.ToDurationDisplayString()}", Job.JobStatus.Delayed => $"until {job.DelayedUntil?.ToDisplayStringTz() ?? ""}", - Job.JobStatus.Running => $"for {job.Duration} ms", Job.JobStatus.Completed => $"at {job.FinishedAt?.ToDisplayStringTz() ?? ""}", Job.JobStatus.Failed => $"at {job.FinishedAt?.ToDisplayStringTz() ?? ""}", _ => throw new ArgumentOutOfRangeException() diff --git a/Iceshrimp.Backend/Pages/QueueJob.cshtml b/Iceshrimp.Backend/Pages/QueueJob.cshtml index a13876f5..a5391677 100644 --- a/Iceshrimp.Backend/Pages/QueueJob.cshtml +++ b/Iceshrimp.Backend/Pages/QueueJob.cshtml @@ -69,20 +69,14 @@ @(Model.Job.DelayedUntil?.ToDisplayStringTz() ?? "") } - @if (Model.Job.Duration < 10000) - { - - Duration - @Model.Job.Duration ms - - } - @if (Model.Job.QueueDuration < 10000) - { - - Queue duration - @Model.Job.QueueDuration ms - - } + + Duration + @Model.Job.Duration.ToDurationDisplayString() + + + Queue duration + @Model.Job.QueueDuration.ToDurationDisplayString() + @if (Model.Job.RetryCount > 0) { @@ -204,4 +198,4 @@ } } - + \ No newline at end of file