Files
ersatztv/ErsatzTV.Infrastructure/Streaming/Graphics/Text/TemplateFunctions.cs
T
Jason DoveandGitHub a6b01cbe28 convert graphics engine from imagesharp to skiasharp (#2319)
* use skiasharp in graphics engine

* start to use richtextkit

* move out some template functions

* move files

* add base graphics element

* use default style in text element

* support partial styling in text element

* fix static images

* load fonts from text element definition
2025-08-15 14:27:22 +00:00

38 lines
1.2 KiB
C#

using System.Globalization;
using Microsoft.Extensions.Logging;
using TimeZoneConverter;
namespace ErsatzTV.Infrastructure.Streaming.Graphics.Text;
public class TemplateFunctions(ILogger<TemplateFunctions> logger)
{
public DateTimeOffset ConvertTimeZone(DateTimeOffset dateTimeOffset, string timeZoneId)
{
try
{
var 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
{
var 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);
}
}