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

Feature/time provider #2612

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Conversation

trejjam
Copy link

@trejjam trejjam commented May 27, 2024

Use TimeProvider instead of DateTime.Now

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • If any gains or losses in performance are possible, you've included benchmarks for your changes. More info
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

This PR adds TimeProvider for .net8+ targets. It's done as an additional property, TimeProvider, on Descriptor/Parameter classes.

Description

I added TimeProvider to nearly all usages of DateTime.Now. Some were too difficult to add (BC Break).

Fixes #2572

@trejjam
Copy link
Author

trejjam commented Jul 26, 2024

Hi. Can you take a look at this? I would love to have some feedback :)

@alexmurari
Copy link

@pmaytak This PR is a follow-up of the previous one you reviewed. We would appreciate your review here too.

Copy link
Member

@brentschmaltz brentschmaltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there are other properties on the TimeProvider we would use besides UtcNow.

</PropertyGroup>

<PropertyGroup Condition=" ($([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '8.0'))) ">
<DefineConstants>$(DefineConstants);SUPPORTS_TIME_PROVIDER</DefineConstants>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a new define and not just NET8+

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a big reason but a matter of personal preference. It allows easy integration of Microsoft.Bcl.TimeProvider if requested.

If you prefer NET8_0_OR_GREATER, I will change it.

@trejjam
Copy link
Author

trejjam commented Aug 2, 2024

There is also available timezone info, GetElapsedTime, a Timer, ...

I prefer to use these in a following PR.

@jennyf19
Copy link
Collaborator

jennyf19 commented Aug 6, 2024

@iNinja and @FuPingFranco (@brentschmaltz ) are you considering this with the changes you are doing to validationParameters?

build/common.props Outdated Show resolved Hide resolved
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.

Use TimeProvider instead of DateTime ambient context
4 participants