-
-
Notifications
You must be signed in to change notification settings - Fork 184
Description
The code to reproduce the issue is very simple:
using Fluid;
var model = new { foo = "bar", date = DateTime.MinValue };
var template = new FluidParser().Parse("{{foo}} {{date}}");
template.Render(new TemplateContext(model))
The exception:
System.ArgumentOutOfRangeException: The UTC time represented when the offset is applied must be between year 0 and 10,000. (Parameter 'offset')
at System.DateTimeOffset.ValidateDate(DateTime dateTime, TimeSpan offset)
at System.DateTimeOffset..ctor(DateTime dateTime)
at System.DateTimeOffset.op_Implicit(DateTime dateTime)
at Fluid.Values.FluidValue.Create(Object value, TemplateOptions options)
at Fluid.Values.ObjectValueBase.GetValueAsync(String name, TemplateContext context)
at Fluid.Ast.IdentifierSegment.ResolveAsync(FluidValue value, TemplateContext context)
at Fluid.Ast.MemberExpression.EvaluateAsync(TemplateContext context)
at Fluid.Ast.OutputStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Parser.FluidTemplate.RenderAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.FluidTemplateExtensions.RenderAsync(IFluidTemplate template, TextWriter textWriter, TemplateContext context, TextEncoder encoder, Boolean isolateContext)
at Fluid.FluidTemplateExtensions.RenderAsync(IFluidTemplate template, TemplateContext context, TextEncoder encoder, Boolean isolateContext)
at Program.<Main>$(String[] args)
An exception is thrown only when the tempalte string contains the date field.
I am using .NET 9.
My timezone is (UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius.
The following workaround makes it work:
using Fluid;
var model = new { foo = "bar", date = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc) }; //same value but Kind = Utc
var template = new FluidParser().Parse("{{foo}} {{date}}");
template.Render(new TemplateContext(model))