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
Allow locally set time references for Date and Faker[T] (#500)
* Move to locally defined DateTime and away from Date.SystemClock.
* Add additional unit tests by @garcipat from #508
* Xml comment fix from @garcipat from #508
* Start documentation on new local/global datetime reference seeding.
* Small tweaks to documentation; use .DateTimeReference property for Faker.
* Give credit to @garcipat for his PR work.
Copy file name to clipboardExpand all lines: HISTORY.md
+4
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,7 @@
1
+
## vNext
2
+
Release Date: Unreleased
3
+
* PR 500: Allows locally set time references for Date calculations instead of global statics. See Faker[T].UseDateTimeReference(), Faker.DateTimeReference, and DataSets.Date.LocalSystemClock. Thanks @garcipat!
4
+
1
5
## v35.4.1
2
6
Release Date: 2024-03-02
3
7
* PR 529: XML Docs: Add inclusive / exclusive number ranges documentation for Randomizer. Thanks @Mitchman215!
// Now use Bogus as you normally would. All dates and times
1048
-
// generated by Bogus should now be deterministic.
1049
-
varp=newPerson();
1050
-
p.DateOfBirth; // 1996-06-09T15:38:11
1051
-
1052
-
varf=newFaker();
1053
-
f.Date.Past(); // 2018-09-29T07:42:26
1054
-
f.Date.Future(); // 2020-02-13T08:10:27
1041
+
// Faker[T]: Set a local seed and a time reference
1042
+
varfakerT=newFaker<Order>()
1043
+
.UseSeed(1338)
1044
+
.UseDateTimeReference(DateTime.Parse("1/1/1980"))
1045
+
.RuleFor(o=>o.SoonValue, f=>f.Date.Soon())
1046
+
.RuleFor(o=>o.RecentValue, f=>f.Date.Recent());
1047
+
fakerT.Generate().Dump();
1048
+
// { "SoonValue": "1980-01-01T17:33:05",
1049
+
// "RecentValue": "1979-12-31T14:07:31" }
1050
+
1051
+
// Faker: Set a local seed and a time reference
1052
+
varfaker=newFaker
1053
+
{
1054
+
Random=newRandomizer(1338),
1055
+
DateTimeReference=DateTime.Parse("1/1/1980")
1056
+
};
1057
+
faker.Date.Soon(); // "1980-01-01T17:33:05"
1058
+
faker.Date.Recent(); // "1979-12-31T14:07:31"
1055
1059
```
1056
-
With the `Bogus.DataSets.Date.SystemClock`set and a [local or global](#determinism) seed, dates and times should be deterministic across multiple runs of a program.
1060
+
With a time reference set and a [seed](#determinism), dates and times should be deterministic across multiple runs of a program.
0 commit comments