mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
37 lines
1.2 KiB
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 |
|
{ |
|
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); |
|
} |
|
}
|
|
|