Skip to content

Commit 867c74d

Browse files
authored
Merge pull request #3 from hbjorgo/ConstantTime
Constant time
2 parents 4387a2a + a7a3879 commit 867c74d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/HeboTech.TimeService/HeboTech.TimeService.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReleaseNotes>https://github.com/hbjorgo/TimeService/releases</PackageReleaseNotes>
1111
<PackageTags>time timeservice time-service timefunc time-func</PackageTags>
1212
<RepositoryUrl>https://github.com/hbjorgo/TimeService</RepositoryUrl>
13-
<Version>1.0.1</Version>
13+
<Version>1.1.0</Version>
1414
</PropertyGroup>
1515

1616
</Project>

src/HeboTech.TimeService/TimeProviders.cs

+7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ namespace HeboTech.TimeService
44
{
55
public class TimeProviders
66
{
7+
/// <summary>
8+
/// Returns DateTime.Now
9+
/// </summary>
710
public static Func<DateTime> SystemTime => () => DateTime.Now;
11+
12+
/// <summary>
13+
/// Returns DateTime.UtcNow
14+
/// </summary>
815
public static Func<DateTime> SystemTimeUtc => () => DateTime.UtcNow;
916
}
1017
}

src/HeboTech.TimeService/TimeService.cs

+15
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@ namespace HeboTech.TimeService
55
public static class TimeService
66
{
77
private static Func<DateTime> timeFunc;
8+
9+
/// <summary>
10+
/// Gets a DateTime object that represents the current time
11+
/// </summary>
812
public static DateTime Now => timeFunc();
913

14+
/// <summary>
15+
/// Sets the current time. The func can either return a constant time, or a dynamic one (like DateTime.Now).
16+
/// </summary>
17+
/// <param name="timeFunc">Func that returns the current time</param>
1018
public static void Set(Func<DateTime> timeFunc) =>
1119
TimeService.timeFunc = timeFunc ?? throw new ArgumentNullException(nameof(timeFunc));
20+
21+
/// <summary>
22+
/// Sets the current (constant) time.
23+
/// </summary>
24+
/// <param name="now">The current (constant) time</param>
25+
public static void SetConstant(DateTime now) =>
26+
timeFunc = () => now;
1227
}
1328
}

0 commit comments

Comments
 (0)