By default, the liquid template outputs UTC format, but we want to give the Template builder the ability to conveniently convert the time to the same time specified in the system configuration settings.
public static ValueTask<FluidValue> LocalDateFilter(FluidValue input, FilterArguments arguments, TemplateContext context)
{
var value = TimeZoneConverter(input, context);
return ReferenceEquals(value, NilValue.Instance) ? value : MiscFilters.Date(value, arguments, context);
}
private static FluidValue TimeZoneConverter(FluidValue input, TemplateContext context)
{
if (!input.TryGetDateTimeInput(context, out var value))
{
return NilValue.Instance;
}
var utc = DateTime.SpecifyKind(value.DateTime, DateTimeKind.Utc);
// Create new offset for UTC
var localOffset = new DateTimeOffset(utc, TimeSpan.Zero);
var result = TimeZoneInfo.ConvertTime(localOffset, context.TimeZone);
return new DateTimeValue(result);
}
And we should update the default template too so this filter is in use for fresh installations.