You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-11Lines changed: 54 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ Timecop is a small library that helps you test DateTime in a static, thread-safe
5
5
6
6
Timecop targets .NET Standard 2.0, has no external dependencies, and can be used with .NET Framework 4.5+ and any version of .NET and .NET Core.
7
7
8
+
Timecop is the C# port of the [timecop](https://github.com/travisjeffery/timecop) Ruby gem.
9
+
8
10
## Installation
9
11
10
12
You can install [Timecop](https://www.nuget.org/packages/Timecop/) from NuGet using the .NET CLI:
@@ -13,14 +15,9 @@ You can install [Timecop](https://www.nuget.org/packages/Timecop/) from NuGet us
13
15
dotnet add package Timecop
14
16
```
15
17
16
-
## Usage
17
-
18
-
Timecop allows freezing and travelling in time. It gives you two classes:
19
-
1.`Clock` - use it instead of `DateTime.Now` and `DateTime.UtcNow`to get the current time
20
-
2.`TimeCop`- use it to manipulate time in tests
21
-
18
+
## Basic usage
22
19
23
-
Timecop can be used in a static context, the same way you would use DateTime:
20
+
Timecop allows you to freeze and travel in time. Just use the `Clock` class instead of `DateTime`to get the current time via `Now` or `UtcNow` properties, and manipulate time with the `Timecop` class in your tests.
tc.TravelBy(TimeSpan.FromHours(6)); // travel to 8pm local time
39
+
// travel to 8pm local time:
40
+
tc.TravelBy(TimeSpan.FromHours(6));
44
41
45
42
Greet(); // Good evening!
46
43
```
47
44
45
+
## Available methods
46
+
47
+
### Freezing and resuming time
48
+
49
+
Time is frozen with either an instance `Freeze` or a static `Frozen` method, both having the same set of signatures. The instance `Freeze` freezes the instance of `Timecop`, the static `Frozen` creates an already frozen instance.
50
+
51
+
Frozen time doesn't run for your tests unless you call `Resume` or dispose the `Timecop` instance:
publicDateTimeKindNotSpecifiedException():base($"Specify either {nameof(DateTimeBuilder.LocalTime)}() or {nameof(DateTimeBuilder.UtcTime)}() when configuring time to freeze.")
0 commit comments