Skip to content

Add Roslyn analyser to block DateTime Now properties - #5904

Closed
rbev wants to merge 4 commits into
masterfrom
time-analyser
Closed

rbev wants to merge 4 commits into
masterfrom
time-analyser

Conversation

@rbev

@rbev rbev commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Follow up from #5843

Adds new entries to the BannedSymbols.txt file to discourage direct usage of certain date and time properties. Instead, it recommends using TimeProvider as a replacement.

@warwickschroeder warwickschroeder left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the BannedSymbols file even used/referenced? There should be warnings but there arnt.

ExpirationDate = DateTime.UtcNow.Date.AddDays(-2), //HasLicenseDateExpired uses a grace period of 1 day

Also, once wired up would throw errors in CI as it treats warnings as errors.

Should "DateTime.Today" be banned as well?

@rbev

rbev commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Is the BannedSymbols file even used/referenced? There should be warnings but there arnt.

ExpirationDate = DateTime.UtcNow.Date.AddDays(-2), //HasLicenseDateExpired uses a grace period of 1 day

Also, once wired up would throw errors in CI as it treats warnings as errors.

Should "DateTime.Today" be banned as well?

That's so strange, I was surprised I got no errors so I added a reference, it wasn't a warning it completely failed the build locally without a #pragma. I didn't go searching, I just assumed you did an amazing job removing them all.

I'll look into why those ones don't create errors.

@rbev rbev changed the title Add roslyn analyser to block DateTime Now properties Add Roslyn analyser to block DateTime Now properties Sep 18, 2026

@johnsimons johnsimons left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we use

dotnet_diagnostic.RS0030.severity = hint

So that devs are aware of it?

Actually, to make sure devs do the right thing, should we use inline pragmas, and not disable it in .editorconfig?

@rbev

rbev commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Abandoning as it was decided that this analyser did not provide enough value while there are so many exceptions in the project.

@rbev rbev closed this Sep 23, 2026
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.

4 participants