* 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
38 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|