Skip to content

Commit 79a31dd

Browse files
use TimeProvider (#452) (#492)
Co-authored-by: Zhiyuan Liang <141655842+zhiyuanliang-ms@users.noreply.github.com>
1 parent 564312d commit 79a31dd

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

src/Microsoft.FeatureManagement/FeatureFilters/ISystemClock.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Microsoft.FeatureManagement/FeatureFilters/TimeWindowFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public TimeWindowFilter(ILoggerFactory loggerFactory = null)
3939
/// <summary>
4040
/// This property allows the time window filter in our test suite to use simulated time.
4141
/// </summary>
42-
internal ISystemClock SystemClock { get; set; }
42+
internal TimeProvider SystemClock { get; set; }
4343

4444
/// <summary>
4545
/// Binds configuration representing filter parameters to <see cref="TimeWindowFilterSettings"/>.
@@ -74,7 +74,7 @@ public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context)
7474
// Check if prebound settings available, otherwise bind from parameters.
7575
TimeWindowFilterSettings settings = (TimeWindowFilterSettings)context.Settings ?? (TimeWindowFilterSettings)BindParameters(context.Parameters);
7676

77-
DateTimeOffset now = SystemClock?.UtcNow ?? DateTimeOffset.UtcNow;
77+
DateTimeOffset now = SystemClock?.GetUtcNow() ?? DateTimeOffset.UtcNow;
7878

7979
if (!settings.Start.HasValue && !settings.End.HasValue)
8080
{
@@ -129,7 +129,7 @@ public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context)
129129

130130
private DateTimeOffset? ReloadClosestStart(TimeWindowFilterSettings settings)
131131
{
132-
DateTimeOffset now = SystemClock?.UtcNow ?? DateTimeOffset.UtcNow;
132+
DateTimeOffset now = SystemClock?.GetUtcNow() ?? DateTimeOffset.UtcNow;
133133

134134
DateTimeOffset? closestStart = RecurrenceEvaluator.CalculateClosestStart(now, settings);
135135

src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
</PropertyGroup>
3838

3939
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
40-
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.1" />
40+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
4141
</ItemGroup>
4242

4343
<ItemGroup>
44+
<PackageReference Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" />
4445
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.1.23" />
4546
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.10" />
4647
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
using Microsoft.FeatureManagement.FeatureFilters;
2-
using System;
1+
using System;
32

43
namespace Tests.FeatureManagement
54
{
6-
class OnDemandClock : ISystemClock
5+
class OnDemandClock : TimeProvider
76
{
87
public DateTimeOffset UtcNow { get; set; }
8+
9+
public override DateTimeOffset GetUtcNow()
10+
{
11+
return UtcNow;
12+
}
913
}
1014
}

0 commit comments

Comments
 (0)