-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed DateTime.Now to use TimeProvider.
Added a new TestTimeProvider to test solution, passed in through options. This allows for easier testing as well as customization for the user in case they want to change provider. Fixed Age tests (provider always returns first day of month, allowing simplified age calculation in tests). Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
- Loading branch information
1 parent
0831d07
commit ad8dcda
Showing
4 changed files
with
51 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
|
||
namespace Personnummer.Tests; | ||
|
||
/// <summary> | ||
/// TimeProvider which always returns the same date: 2025 01 01 00:00:01 with UTC timezone on local time. | ||
/// </summary> | ||
public class TestTimeProvider : TimeProvider | ||
{ | ||
public override DateTimeOffset GetUtcNow() | ||
{ | ||
return new DateTimeOffset( | ||
new DateOnly(2025, 1, 1), | ||
new TimeOnly(0,0,0, 1), | ||
TimeSpan.Zero | ||
); | ||
} | ||
|
||
public override TimeZoneInfo LocalTimeZone { get; } = TimeZoneInfo.Utc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters