diff --git a/Fluid.Tests/MiscFiltersTests.cs b/Fluid.Tests/MiscFiltersTests.cs
index 837e76e4..2c3e7aaa 100644
--- a/Fluid.Tests/MiscFiltersTests.cs
+++ b/Fluid.Tests/MiscFiltersTests.cs
@@ -409,6 +409,23 @@ public async Task DateNumberIsParsedAsSeconds(long number, string expected)
Assert.Equal(expected, result.ToStringValue());
}
+ [Theory]
+ [InlineData("0", "00:00:00.000")]
+ [InlineData("1:2", "01:02:00.000")]
+ [InlineData("1:2:3.1", "01:02:03.100")]
+ public async Task DateTimeSpan(string timespan, string expected)
+ {
+ // Converting to Unix time should not vary by TimeSone
+
+ var input = FluidValue.Create(TimeSpan.Parse(timespan), new TemplateOptions());
+ var format = new FilterArguments(new StringValue("%H:%M:%S.%L"));
+ var context = new TemplateContext { TimeZone = Eastern };
+
+ var result = await MiscFilters.Date(input, format, context);
+
+ Assert.Equal(expected, result.ToStringValue());
+ }
+
[Fact]
public async Task NoTimeZoneIsParsedAsLocal()
{
diff --git a/Fluid/MemberAccessStrategyExtensions.cs b/Fluid/MemberAccessStrategyExtensions.cs
index 0d6e381c..2e3526af 100644
--- a/Fluid/MemberAccessStrategyExtensions.cs
+++ b/Fluid/MemberAccessStrategyExtensions.cs
@@ -80,7 +80,7 @@ internal static IMemberAccessor GetNamedAccessor(Type type, string name, MemberN
///
/// The type to register.
/// The .
- public static void Register(this MemberAccessStrategy strategy)
+ public static void Register(this MemberAccessStrategy strategy) where T : class
{
Register(strategy, typeof(T));
}
@@ -101,7 +101,7 @@ public static void Register(this MemberAccessStrategy strategy, Type type)
/// The type to register.
/// The .
/// The names of the properties in the type to register.
- public static void Register(this MemberAccessStrategy strategy, params string[] names)
+ public static void Register(this MemberAccessStrategy strategy, params string[] names) where T : class
{
strategy.Register(typeof(T), names);
}
@@ -112,7 +112,7 @@ public static void Register(this MemberAccessStrategy strategy, params string
/// The type to register.
/// The .
/// The property's expressions in the type to register.
- public static void Register(this MemberAccessStrategy strategy, params Expression>[] names)
+ public static void Register(this MemberAccessStrategy strategy, params Expression>[] names) where T : class
{
strategy.Register(names.Select(ExpressionHelper.GetPropertyName).ToArray());
}
diff --git a/Fluid/Values/FluidValue.cs b/Fluid/Values/FluidValue.cs
index 7e4ea137..15584ecf 100644
--- a/Fluid/Values/FluidValue.cs
+++ b/Fluid/Values/FluidValue.cs
@@ -166,6 +166,9 @@ public static FluidValue Create(object value, TemplateOptions options)
case DateTimeOffset dateTimeOffset:
return new DateTimeValue(dateTimeOffset);
+ case TimeSpan timeSpan:
+ return new DateTimeValue(new DateTime(timeSpan.Ticks));
+
case IFormattable formattable:
return new StringValue(formattable.ToString(null, options.CultureInfo));