Skip to content

Commit

Permalink
Date filter returns input value as date when not filter is specified (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros authored Dec 20, 2022
1 parent 9bdcf87 commit 7cb3357
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Fluid.Tests/MiscFiltersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,20 @@ public async Task DateIsParsed()
Assert.Equal("08/01/17", result.ToStringValue());
}

[Fact]
public async Task DateWithoutFormatShouldReturnInput()
{
var input = new StringValue("08/01/2017");

var options = new TemplateOptions() { CultureInfo = CultureInfo.InvariantCulture, TimeZone = TimeZoneInfo.Utc };
var context = new TemplateContext(options);

var result = await MiscFilters.Date(input, FilterArguments.Empty, context);

Assert.IsType<DateTimeValue>(result);
Assert.Equal("2017-08-01 00:00:00Z", result.ToStringValue());
}

[Theory]
[InlineData(0, "1969-12-31T19:00:00.000-05:00")]
[InlineData(10, "1969-12-31T19:00:10.000-05:00")]
Expand Down
2 changes: 1 addition & 1 deletion Fluid/Filters/MiscFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public static ValueTask<FluidValue> Date(FluidValue input, FilterArguments argum

if (arguments.At(0).IsNil())
{
return NilValue.Instance;
return new DateTimeValue(value);
}

var format = arguments.At(0).ToStringValue();
Expand Down

0 comments on commit 7cb3357

Please sign in to comment.