@@ -5,7 +5,7 @@ Timecop is a small library that helps you test DateTime in a static, thread-safe
55
66Timecop 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.
77
8- Timecop is the C# port of the [ timecop] ( https://github.com/travisjeffery/timecop ) Ruby gem.
8+ Timecop has been inspired by the [ timecop] ( https://github.com/travisjeffery/timecop ) Ruby gem.
99
1010## Installation
1111
@@ -32,10 +32,12 @@ string Greet()
3232
3333 return $" Good {timeOfDay }!" ;
3434}
35+
3536// freeze at 2pm local time:
3637using var tc = Timecop .Frozen (o => o .At (14 ,0 ,0 ).LocalTime ());
3738
3839Greet (); // Good afternoon!
40+
3941// travel to 8pm local time:
4042tc .TravelBy (TimeSpan .FromHours (6 ));
4143
@@ -48,32 +50,39 @@ Greet(); // Good evening!
4850
4951Time 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.
5052
51- Frozen time doesn't run for your tests unless you call ` Resume ` or dispose the ` Timecop ` instance:
53+ Frozen time doesn't run for your tests until you call ` Resume ` or dispose the ` Timecop ` instance:
5254
5355``` csharp
5456using var tc = Timecop .Frozen (1990 , 12 , 2 , 14 , 38 , 51 , DateTimeKind .Local );
57+
5558Clock .Now ; // 1990-12-02 14:38:51
5659
5760Thread .Sleep (TimeSpan .FromSeconds (3 ));
58- Clock .Now ; // 1990-12-02 14:38:51 - Still the same value
61+
62+ Clock .Now ; // 1990-12-02 14:38:51 - still the same value
5963
6064tc .Resume ();
6165
6266Thread .Sleep (TimeSpan .FromSeconds (3 ));
63- Clock .Now ; // 1990-12-02 14:38:54 - Time has changed
67+
68+ Clock .Now ; // 1990-12-02 14:38:54 - time has changed
6469```
6570
66- Both ` Freeze ` and ` Frozen ` have the multiple overloads:
71+ Both ` Freeze ` and ` Frozen ` have multiple overloads:
6772
6873``` csharp
6974// freeze at the current instant:
7075tc .Freeze ();
76+
7177// freeze at the specified DateTime:
7278tc .Freeze (new DateTime (1990 , 12 , 2 , 14 , 38 , 51 , DateTimeKind .Utc ));
79+
7380// freeze at the specified date and time:
7481tc .Freeze (1990 , 12 , 2 , 14 , 38 , 51 , DateTimeKind .Utc );
82+
7583// freeze at the specified date:
7684tc .Freeze (1990 , 12 , 2 , DateTimeKind .Utc );
85+
7786// freeze at the specified date or time or both:
7887tc .Freeze (o => o .On (1990 , 12 , 2 )
7988 .At (14 , 13 , 51 )
@@ -86,9 +95,12 @@ Use the `TravelBy` method to travel forward and backward in time:
8695
8796``` csharp
8897using var tc = Timecop .Frozen (1990 , 12 , 2 , 14 , 38 , 51 , DateTimeKind .Local );
98+
8999tc .TravelBy (TimeSpan .FromDays (1 ));
90- Clock .Now ; // 1990-12-03 14:38:51 - One day in the future
100+
101+ Clock .Now ; // 1990-12-03 14:38:51 - one day in the future
91102```
103+
92104## License
93105
94106Timecop was created by [ Dmytro Khmara] ( https://dmytrokhmara.com ) and is licensed under the [ MIT license] ( LICENSE.txt ) .
0 commit comments