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

Create rule S6575: Use TimeZoneInfo.FindSystemTimeZoneById instead of TimezoneConverter #1729

Merged
merged 15 commits into from
Jul 4, 2023

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Apr 5, 2023

You can preview this rule here (updated a few minutes after each push).

This rule should raise when the project targets .net6 and TimeZoneConverter methods for IANA and Windows Timezones are used.

  • IanaToWindows
  • WindowsToIana
  • TryIanaToWindows
  • TryWindowsToIana

TimeZoneConverter also covers Rails Timezones - we should not raise there as imeZoneInfo.FindSystemTimeZoneById does not cover these.

@github-actions github-actions bot added the dotnet label Apr 5, 2023
@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title Create rule S6575 Create rule S6575: Use TimeZoneInfo.FindSystemTimeZoneById instead of TimezoneConverter Apr 5, 2023
@mary-georgiou-sonarsource mary-georgiou-sonarsource force-pushed the rule/add-RSPEC-S6575 branch 3 times, most recently from 76a73b8 to cd0bb60 Compare April 6, 2023 14:26
Copy link
Contributor

@csaba-sagi-sonarsource csaba-sagi-sonarsource left a comment

Choose a reason for hiding this comment

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

Please take a look at the comment I left, it might be that the rule will not be able to cover all cases.

Copy link
Contributor

@csaba-sagi-sonarsource csaba-sagi-sonarsource left a comment

Choose a reason for hiding this comment

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

Like the rspec a lot, I left a few minor comments, and please address the formatting and common parts sharing between C# and VB.NET

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! Please fix the variable name on the snippet

rules/S6575/csharp/rule.adoc Outdated Show resolved Hide resolved
Copy link
Contributor

@csaba-sagi-sonarsource csaba-sagi-sonarsource left a comment

Choose a reason for hiding this comment

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

Round 2.

Copy link
Contributor

@csaba-sagi-sonarsource csaba-sagi-sonarsource left a comment

Choose a reason for hiding this comment

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

One last round.

@@ -0,0 +1,4 @@
== How to fix it

There's no need to translate manually between time zones; it is enough `TimeZoneInfo.FindSystemTimeZoneById(string timezone)`, where the timezone can be IANA or Windows format.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
There's no need to translate manually between time zones; it is enough `TimeZoneInfo.FindSystemTimeZoneById(string timezone)`, where the timezone can be IANA or Windows format.
There's no need to translate manually between time zones; it is enough to call `TimeZoneInfo.FindSystemTimeZoneById(string timezone)`, where the timezone can be IANA or Windows format.

Copy link
Contributor

Choose a reason for hiding this comment

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

The "to call" should go before the method name, no?

Copy link
Contributor

@csaba-sagi-sonarsource csaba-sagi-sonarsource left a comment

Choose a reason for hiding this comment

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

I approved, please fix the one last remaining issue.

Copy link
Contributor

@cynthiabethea cynthiabethea left a comment

Choose a reason for hiding this comment

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

one suggested text change

== Why is this an issue?

The method `TimeZoneInfo.FindSystemTimeZoneById(string timezone)` can get both IANA and Windows timezones as input and automatically convert one to the other if the requested time zone is not found on the system.
This means that one does not have to handle the conversion and make the code more complicated and thus more difficult to maintain.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change this to: "Because one does not need to handle the conversion the code will be less complex and easier to maintain."

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-frontend'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-tools'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-tools'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-frontend'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-tools'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-frontend'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-tools'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-frontend'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@csaba-sagi-sonarsource csaba-sagi-sonarsource marked this pull request as ready for review July 4, 2023 09:29
@csaba-sagi-sonarsource csaba-sagi-sonarsource merged commit 4d5467c into master Jul 4, 2023
@csaba-sagi-sonarsource csaba-sagi-sonarsource deleted the rule/add-RSPEC-S6575 branch July 4, 2023 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants