Files
ersatztv/ErsatzTV.Infrastructure/Streaming/Graphics/Text/TemplateFunctions.cs
T
Jason DoveandGitHub 5d081ceeff fix editorconfig and run code cleanup (#2324)
* fix formatting rules

* reformat ersatztv

* reformat ersatztv.application

* reformat ersatztv.core

* refactor ersatztv.core.tests

* reformat ersatztv.ffmpeg

* reformat ersatztv.ffmpeg.tests

* reformat ersatztv.infrastructure

* cleanup infra mysql

* cleanup infra sqlite

* cleanup infra tests

* cleanup ersatztv.scanner

* cleanup ersatztv.scanner.tests

* sln cleanup

* update dependencies
2025-08-16 14:44:48 +00:00

38 lines
1.2 KiB
C#

using System.Globalization;
using Microsoft.Extensions.Logging;
using TimeZoneConverter;
namespace ErsatzTV.Infrastructure.Streaming.Graphics;
public class TemplateFunctions(ILogger<TemplateFunctions> logger)
{
public DateTimeOffset ConvertTimeZone(DateTimeOffset dateTimeOffset, string timeZoneId)
{
try
{
TimeZoneInfo tz = TZConvert.GetTimeZoneInfo(timeZoneId);
return TimeZoneInfo.ConvertTime(dateTimeOffset, tz);
}
catch (TimeZoneNotFoundException ex)
{
logger.LogWarning(ex, "Exception finding specified time zone; resulting time will be unchanged");
return dateTimeOffset;
}
}
public string FormatDateTime(DateTimeOffset dateTimeOffset, string timeZoneId, string format)
{
try
{
TimeZoneInfo tz = TZConvert.GetTimeZoneInfo(timeZoneId);
dateTimeOffset = TimeZoneInfo.ConvertTime(dateTimeOffset, tz);
}
catch (TimeZoneNotFoundException ex)
{
logger.LogWarning(ex, "Exception finding specified time zone; resulting time will be unchanged");
}
return dateTimeOffset.ToString(format, CultureInfo.CurrentCulture);
}
}