Skip to content

Commit 2ecda18

Browse files
authored
Fix DateTimeHelper (#120)
1 parent bf92084 commit 2ecda18

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Handlebars.Net.Helpers/Helpers/DateTimeHelpers.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
namespace HandlebarsDotNet.Helpers.Helpers;
88

9-
internal class DateTimeHelpers(IHandlebars context, IDateTimeService dateTimeService) : StringHelpers(context)
9+
internal class DateTimeHelpers(IHandlebars context, IDateTimeService dateTimeService) : BaseHelpers(context), IHelpers
1010
{
1111
private readonly IDateTimeService _dateTimeService = Guard.NotNull(dateTimeService);
12+
private readonly StringHelpers _stringHelpers = new(context);
1213

1314
[HandlebarsWriter(WriterType.Value)]
1415
public object Now(string? format = null)
@@ -25,12 +26,12 @@ public object UtcNow(string? format = null)
2526
}
2627

2728
[HandlebarsWriter(WriterType.String, Name = "DateTime.Format")]
28-
public override string Format(object? value, string format)
29+
public string Format(object? value, string format)
2930
{
3031
return value switch
3132
{
32-
DateTime valueAsDateTime => base.Format(valueAsDateTime, format),
33-
string valueAsString when DateTime.TryParse(valueAsString, out var parsedAsDateTime) => base.Format(parsedAsDateTime, format),
33+
DateTime valueAsDateTime => _stringHelpers.Format(valueAsDateTime, format),
34+
string valueAsString when DateTime.TryParse(valueAsString, out var parsedAsDateTime) => _stringHelpers.Format(parsedAsDateTime, format),
3435
_ => string.Empty
3536
};
3637
}
@@ -130,5 +131,5 @@ private DateTime GetDateTimeNonNullable(object value, string? format)
130131
return Guard.NotNull(GetDatetime(Guard.NotNull(value), format)).GetValueOrDefault();
131132
}
132133

133-
public override Category Category => Category.DateTime;
134+
public Category Category => Category.DateTime;
134135
}

src/Handlebars.Net.Helpers/Helpers/StringHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,5 +455,5 @@ public WrappedString ToWrappedString(object? value)
455455
return FormatAsString(value);
456456
}
457457

458-
public virtual Category Category => Category.String;
458+
public Category Category => Category.String;
459459
}

0 commit comments

Comments
 (0)