Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow locally set time references for Date and Faker[T] #500

Merged
merged 6 commits into from
Mar 9, 2024

Conversation

bchavez
Copy link
Owner

@bchavez bchavez commented Sep 23, 2023

Allows locally set time references for Date calculations instead of global statics. See Faker[T].UseDateTimeReference() and Date.LocalSystemClock. Alternative PR to #492.

@bchavez bchavez mentioned this pull request Sep 23, 2023
@garcipat
Copy link

I like the setting as with the seed. This makes logically a lot of sense and is cleaner then having a property to set.

@bchavez
Copy link
Owner Author

bchavez commented Sep 23, 2023

I like the setting as with the seed. This makes logically a lot of sense and is cleaner then having a property to set.

@garcipat I think I agree. Perhaps we can [Obsolete] .UseSeed(int) in favor of .UseSeed(int, refDate); but I would probably still keep Faker<T>.UseDateTimeReference() since it could be used with Faker<T>.Clone() more flexibly.

@garcipat
Copy link

garcipat commented Sep 23, 2023

I like the setting as with the seed. This makes logically a lot of sense and is cleaner then having a property to set.

@garcipat I think I agree. Perhaps we can [Obsolete] .UseSeed(int) in favor of .UseSeed(int, refDate); but I would probably still keep Faker<T>.UseDateTimeReference() since it could be used with Faker<T>.Clone() more flexibly.

@bchavez No what I meant I like the UseDateTimeReference method over setting it as a property as I did it in the PR #492. I think you should keep the UseSeed separated. Both make something completly different and it's more a fluent synthax like that.

@garcipat
Copy link

garcipat commented Sep 23, 2023

TODO: Also write some tests for NET6 only for DateOnly and TimeOnly since we might have missed a code change in #492

@bchavez If you like I write a test for every method. I dont know if you need to have all of them covered with the relative or if one with DateOnly and one with TimeOnly already covers enough. I can do it in the other PR and you can take it over and tweak it. To spare you some time.

@bchavez bchavez force-pushed the local-system-clock branch 2 times, most recently from 610cb64 to 4a22cdd Compare October 8, 2023 16:46
@bchavez
Copy link
Owner Author

bchavez commented Oct 8, 2023

API surface so far:

//configuring per Faker[T] instance
var fakerT = new Faker<T>()
     .UseSeed(1337)
     .UseDateTimeReference(new DateTime(2022, 1, 23))

//configuring per Faker instance
var faker = new Faker()
{
     Random = new Randomizer(1337),
     DateTimeReference = new DateTime(2022, 1, 23)
}

//configuring per Date dataset instance
var dateDataSet = new Date()
{
     Random = new Randomizer(1337),
     LocalSystemClock = () => new DateTime(2022, 1, 23)
}

I'm thinking so far, seems DateTimeReference is a bit generic; maybe something like:

  • FixedTimeReference or
  • UseLocalSystemClock or
  • DateTimeAnchor

is more semantically accurate. The only good thing about DateTimeReference is that it's kind of discoverable when f => f.Date is typed in VIsual Studio.

garcipat added a commit to garcipat/Bogus that referenced this pull request Oct 14, 2023

Verified

This commit was signed with the committer’s verified signature.
wagoodman Alex Goodman
@garcipat
Copy link

garcipat commented Oct 14, 2023

@bchavez Now I'm really confused 😅. I cannot work on this PR I think (or can I? thought I cannot push here, or can I just don't make own branches?). Therefore I took over all your changes to the #492 and added tests and things there since thats the only thing I can do.

@bchavez bchavez force-pushed the local-system-clock branch from 4d1bfa9 to 6bfec5c Compare October 15, 2023 18:30
@garcipat
Copy link

garcipat commented Oct 15, 2023

My recent changes on my branch are not in the PR #492 anymore since you closed it, but on the same branch. Just becasue I think now you did not pull over the recent changes where I took over most of your changes in this branch and its mixed up now :(

@bchavez
Copy link
Owner Author

bchavez commented Oct 15, 2023

@garcipat ; what particular tests do you want me to pull over from #492 ?

@bchavez bchavez force-pushed the local-system-clock branch from 27434d7 to 246fb8d Compare October 15, 2023 20:44
@garcipat
Copy link

garcipat commented Oct 15, 2023

@garcipat ; what particular tests do you want me to pull over from #492 ?

@bchavez the PR does not contain my recent changes since it was closed before that.
I just want to prevent that you take over code that you wrote better and is replaced even on my branch.
Should I reopen the PR? or is that even possible?

I'm talking about the changes I did yesterday as promised. For all the operations that reference the GetTimeReference() you wrote I added a test for regular and Offset methods to cover all the cases (mainly here) and also the corrections in the comments that reference DateTime.Now.

@garcipat
Copy link

Ah I see you wrote the tests yourself now. Well I dont know anymore then. I think I will leave it to you since it seems I'm only doing everything in parallel while trying to help adding the missing things.

@bchavez
Copy link
Owner Author

bchavez commented Oct 15, 2023

@garcipat hmm. closing the PR should not have any impact on what was committed; or what previously & currently exists on your fork:

The only way something could be "lost" is if you pushed some code locally to your fork that wasn't totally in-sync with what you pushed to your fork/remote.

That said tho, I think we should continue to focus energy on PR #500 since this is the PR we will go with; I'm just putting the final touches on the public API surface:

  • Faker<T>.UseDateTimeReference()
  • Faker<T>.UseFixedTimeReference()
  • Faker<T>.UseDateTimeAnchor()
  • Faker<T>.UseLocalSystemClock()

Right now, kinda leaning to renaming .UseDateTimeReference() -> .UseDateTimeAnchor()

@garcipat
Copy link

garcipat commented Oct 15, 2023

@garcipat hmm. closing the PR should not have any impact on what was committed; or what previously & currently exists on your fork:

The only way something could be "lost" is if you pushed some code locally to your fork that wasn't totally in-sync with what you pushed to your fork/remote.

That said tho, I think we should continue to focus energy on PR #500 since this is the PR we will go with; I'm just putting the final touches on the public API surface:

  • Faker<T>.UseDateTimeReference()
  • Faker<T>.UseFixedTimeReference()
  • Faker<T>.UseDateTimeAnchor()
  • Faker<T>.UseLocalSystemClock()

Right now, kinda leaning to renaming .UseDateTimeReference() -> .UseDateTimeAnchor()

Can I push to that branch? With "focus energy in that branch" would require me to be able to do that. Otherwise I cannot help. I can push the same changes there to if its technically possible. I will try I guess.

Regarding the proposals, I would lean to the firstor the third. The seconds feels very technical and not so semantically and The "Local" in the last could be confusing about the Local/Utc DateTimeKind because of the wording.

One thing that would give UseDateTimeReference a +1 is, that all arguments in the Api are called refDate. Therefore this would be aligned with that.

Edit: Yes just tried. I can't commit to this branch either. You have to take the changes over manually from my branch if you want them.

@bchavez bchavez force-pushed the master branch 7 times, most recently from a0a12cd to ffa36ce Compare December 22, 2023 18:23
@bchavez bchavez force-pushed the master branch 10 times, most recently from 0b65acc to cc799df Compare December 22, 2023 19:04
@304NotModified
Copy link

@bchavez what should be done to get this feature merged?

It still would be great if we had this!

@bchavez
Copy link
Owner Author

bchavez commented Feb 24, 2024

@304NotModified i think the first thing is to get this rebased to master. then finally, one final review push/reading through the context on this ticket to make sure I'm not missing anything. and also some README documentation changes.

Currently, getting taxes done is my main blocker on any open-source work/releases atm. I'll try to get this branch rebased this weekend.

Verified

This commit was signed with the committer’s verified signature.
wagoodman Alex Goodman
@bchavez bchavez force-pushed the local-system-clock branch from ac42247 to 3ddb371 Compare March 2, 2024 20:19
bchavez added 2 commits March 2, 2024 14:05

Verified

This commit was signed with the committer’s verified signature.
wagoodman Alex Goodman

Verified

This commit was signed with the committer’s verified signature.
wagoodman Alex Goodman
@bchavez bchavez force-pushed the local-system-clock branch from c60535b to 5eb7adf Compare March 2, 2024 21:13

Verified

This commit was signed with the committer’s verified signature.
wagoodman Alex Goodman
@bchavez bchavez force-pushed the local-system-clock branch from d60c2cc to 9a1be0d Compare March 2, 2024 23:01

Verified

This commit was signed with the committer’s verified signature.
wagoodman Alex Goodman
…ker.
@bchavez bchavez force-pushed the local-system-clock branch from d9f349a to 18f8a52 Compare March 2, 2024 23:12

Verified

This commit was signed with the committer’s verified signature.
wagoodman Alex Goodman
@bchavez
Copy link
Owner Author

bchavez commented Mar 2, 2024

@304NotModified and @garcipat, i think this PR is just about ready. I'm planning on merging it next weekend.

@garcipat, I pulled in your tests from PR #508 and gave you credit on the HISTORY.md file.

Let me know if there's any major concerns with the PR before we merge next weekend. README.md documentation on Deterministic Dates and Times should be current with this PR.

@304NotModified
Copy link

Excellent news!

@garcipat
Copy link

garcipat commented Mar 3, 2024

@304NotModified and @garcipat, i think this PR is just about ready. I'm planning on merging it next weekend.

@garcipat, I pulled in your tests from PR #508 and gave you credit on the HISTORY.md file.

Let me know if there's any major concerns with the PR before we merge next weekend. README.md documentation on Deterministic Dates and Times should be current with this PR.

Thank you so much. I feel honored and am very happy that I could contribute something!

@bchavez bchavez merged commit d9d91cd into master Mar 9, 2024
2 checks passed
@bchavez bchavez deleted the local-system-clock branch March 9, 2024 19:38
@bchavez
Copy link
Owner Author

bchavez commented Mar 9, 2024

Changes are released in Bogus v35.5.0:

Let me know if there are any issues. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants