From 553c5f66c4021f26d585caf0701020b7232e0f0b Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini <114916336+cristian-ambrosini-sonarsource@users.noreply.github.com> Date: Wed, 5 Jul 2023 10:56:38 +0200 Subject: [PATCH] New rule S6566: Always use DateTimeOffset instead of DateTime (#7523) --- ...5E-C6AE-4D2D-A9DD-B6EFD19A4279}-S6566.json | 56 ++ ...AF-4FDC-416A-B3E0-968C1C8F3F83}-S6566.json | 82 +++ ...31-1F7B-4637-9B3A-806988DE50CF}-S6566.json | 56 ++ .../expected/Nancy/Nancy--net452-S6566.json | 69 +++ .../Nancy/Nancy--netstandard2.0-S6566.json | 69 +++ ...cy.Authentication.Forms--net452-S6566.json | 17 + ...ntication.Forms--netstandard2.0-S6566.json | 17 + ...Nancy.ViewEngines.Spark--net452-S6566.json | 17 + ...6-462B-BFAC-33B3491365B5-net5.0-S6566.json | 17 + ...D-48B4-AE0B-D9A643E16D1F-net5.0-S6566.json | 17 + .../akka.net/Akka--netstandard2.0-S6566.json | 238 ++++++++ .../Akka.Cluster--netstandard2.0-S6566.json | 147 +++++ ...Cluster.Metrics--netstandard2.0-S6566.json | 17 + ...luster.Sharding--netstandard2.0-S6566.json | 43 ++ ...a.Cluster.Tools--netstandard2.0-S6566.json | 17 + ...DistributedData--netstandard2.0-S6566.json | 199 ++++++ ...kka.MultiNodeTestRunner--net471-S6566.json | 17 + ...kka.MultiNodeTestRunner--net5.0-S6566.json | 17 + ...tiNodeTestRunner--netcoreapp3.1-S6566.json | 17 + ...stRunner.Shared--netstandard2.0-S6566.json | 576 ++++++++++++++++++ ...kka.Persistence--netstandard2.0-S6566.json | 212 +++++++ ...ence.Sql.Common--netstandard2.0-S6566.json | 56 ++ ...sistence.Sqlite--netstandard2.0-S6566.json | 17 + ...Persistence.TCK--netstandard2.0-S6566.json | 17 + .../Akka.Remote--netstandard2.0-S6566.json | 56 ++ .../Akka.Streams--netstandard2.0-S6566.json | 251 ++++++++ ...Streams.TestKit--netstandard2.0-S6566.json | 30 + .../Akka.TestKit--netstandard2.0-S6566.json | 17 + ...ests.Performance--netcoreapp3.1-S6566.json | 30 + .../PersistenceBenchmark--net471-S6566.json | 30 + analyzers/rspec/cs/S6566.html | 48 ++ analyzers/rspec/cs/S6566.json | 15 + analyzers/rspec/vbnet/S6566.html | 48 ++ analyzers/rspec/vbnet/S6566.json | 15 + .../UseDateTimeInsteadOfDateTimeOffset.cs | 29 + .../UseDateTimeInsteadOfDateTimeOffsetBase.cs | 81 +++ .../UseDateTimeInsteadOfDateTimeOffset.cs | 29 + .../PackagingTests/RuleTypeMappingCS.cs | 2 +- .../PackagingTests/RuleTypeMappingVB.cs | 2 +- .../UseDateTimeInsteadOfDateTimeOffsetTest.cs | 51 ++ ...DateTimeInsteadOfDateTimeOffset.CSharp9.cs | 13 + .../UseDateTimeInsteadOfDateTimeOffset.Net.vb | 20 + .../UseDateTimeInsteadOfDateTimeOffset.cs | 98 +++ .../UseDateTimeInsteadOfDateTimeOffset.vb | 96 +++ 44 files changed, 2966 insertions(+), 2 deletions(-) create mode 100644 analyzers/its/expected/Ember-MM/EmberAPI-{208AA35E-C6AE-4D2D-A9DD-B6EFD19A4279}-S6566.json create mode 100644 analyzers/its/expected/Ember-MM/generic.EmberCore.Extractor-{B413DEAF-4FDC-416A-B3E0-968C1C8F3F83}-S6566.json create mode 100644 analyzers/its/expected/Ember-MM/scraper.EmberCore.XML-{E567C031-1F7B-4637-9B3A-806988DE50CF}-S6566.json create mode 100644 analyzers/its/expected/Nancy/Nancy--net452-S6566.json create mode 100644 analyzers/its/expected/Nancy/Nancy--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/Nancy/Nancy.Authentication.Forms--net452-S6566.json create mode 100644 analyzers/its/expected/Nancy/Nancy.Authentication.Forms--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/Nancy/Nancy.ViewEngines.Spark--net452-S6566.json create mode 100644 analyzers/its/expected/Net5/jsonserializerrecords-38409230-12D6-462B-BFAC-33B3491365B5-net5.0-S6566.json create mode 100644 analyzers/its/expected/Net5/recordswithstatichelper-541512C1-D79D-48B4-AE0B-D9A643E16D1F-net5.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Cluster.Metrics--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Cluster.Sharding--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Cluster.Tools--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.DistributedData--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--net471-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--net5.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--netcoreapp3.1-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner.Shared--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Persistence.Sqlite--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Persistence.TCK--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Remote--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Streams--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Streams.TestKit--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.TestKit--netstandard2.0-S6566.json create mode 100644 analyzers/its/expected/akka.net/Akka.Tests.Performance--netcoreapp3.1-S6566.json create mode 100644 analyzers/its/expected/akka.net/PersistenceBenchmark--net471-S6566.json create mode 100644 analyzers/rspec/cs/S6566.html create mode 100644 analyzers/rspec/cs/S6566.json create mode 100644 analyzers/rspec/vbnet/S6566.html create mode 100644 analyzers/rspec/vbnet/S6566.json create mode 100644 analyzers/src/SonarAnalyzer.CSharp/Rules/UseDateTimeInsteadOfDateTimeOffset.cs create mode 100644 analyzers/src/SonarAnalyzer.Common/Rules/UseDateTimeInsteadOfDateTimeOffsetBase.cs create mode 100644 analyzers/src/SonarAnalyzer.VisualBasic/Rules/UseDateTimeInsteadOfDateTimeOffset.cs create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/Rules/UseDateTimeInsteadOfDateTimeOffsetTest.cs create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.CSharp9.cs create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.Net.vb create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.cs create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.vb diff --git a/analyzers/its/expected/Ember-MM/EmberAPI-{208AA35E-C6AE-4D2D-A9DD-B6EFD19A4279}-S6566.json b/analyzers/its/expected/Ember-MM/EmberAPI-{208AA35E-C6AE-4D2D-A9DD-B6EFD19A4279}-S6566.json new file mode 100644 index 00000000000..d0e783f549f --- /dev/null +++ b/analyzers/its/expected/Ember-MM/EmberAPI-{208AA35E-C6AE-4D2D-A9DD-B6EFD19A4279}-S6566.json @@ -0,0 +1,56 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPICommon.vb", +"region": { +"startLine": 711, +"startColumn": 34, +"endLine": 711, +"endColumn": 70 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPICommon.vb", +"region": { +"startLine": 716, +"startColumn": 34, +"endLine": 716, +"endColumn": 70 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIErrorLog.vb", +"region": { +"startLine": 60, +"startColumn": 63, +"endLine": 60, +"endColumn": 71 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIScanner.vb", +"region": { +"startLine": 32, +"startColumn": 30, +"endLine": 32, +"endColumn": 42 +} +} +} +] +} diff --git a/analyzers/its/expected/Ember-MM/generic.EmberCore.Extractor-{B413DEAF-4FDC-416A-B3E0-968C1C8F3F83}-S6566.json b/analyzers/its/expected/Ember-MM/generic.EmberCore.Extractor-{B413DEAF-4FDC-416A-B3E0-968C1C8F3F83}-S6566.json new file mode 100644 index 00000000000..9069884175e --- /dev/null +++ b/analyzers/its/expected/Ember-MM/generic.EmberCore.Extractor-{B413DEAF-4FDC-416A-B3E0-968C1C8F3F83}-S6566.json @@ -0,0 +1,82 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\generic.EmberCore.Extractor\clsExtractor.vb", +"region": { +"startLine": 185, +"startColumn": 91, +"endLine": 185, +"endColumn": 99 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\generic.EmberCore.Extractor\clsExtractor.vb", +"region": { +"startLine": 185, +"startColumn": 145, +"endLine": 185, +"endColumn": 153 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\generic.EmberCore.Extractor\frmMovieExtractor.vb", +"region": { +"startLine": 31, +"startColumn": 67, +"endLine": 31, +"endColumn": 75 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\generic.EmberCore.Extractor\frmMovieExtractor.vb", +"region": { +"startLine": 31, +"startColumn": 121, +"endLine": 31, +"endColumn": 129 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\generic.EmberCore.Extractor\frmTVExtrator.vb", +"region": { +"startLine": 62, +"startColumn": 91, +"endLine": 62, +"endColumn": 99 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\generic.EmberCore.Extractor\frmTVExtrator.vb", +"region": { +"startLine": 62, +"startColumn": 145, +"endLine": 62, +"endColumn": 153 +} +} +} +] +} diff --git a/analyzers/its/expected/Ember-MM/scraper.EmberCore.XML-{E567C031-1F7B-4637-9B3A-806988DE50CF}-S6566.json b/analyzers/its/expected/Ember-MM/scraper.EmberCore.XML-{E567C031-1F7B-4637-9B3A-806988DE50CF}-S6566.json new file mode 100644 index 00000000000..d56667e3201 --- /dev/null +++ b/analyzers/its/expected/Ember-MM/scraper.EmberCore.XML-{E567C031-1F7B-4637-9B3A-806988DE50CF}-S6566.json @@ -0,0 +1,56 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\scraper.EmberCore.XML\XMLScraper\MediaTags\MediaTag.vb", +"region": { +"startLine": 59, +"startColumn": 34, +"endLine": 59, +"endColumn": 42 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\scraper.EmberCore.XML\XMLScraper\ScraperLib\Scraper.vb", +"region": { +"startLine": 69, +"startColumn": 31, +"endLine": 69, +"endColumn": 39 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\scraper.EmberCore.XML\XMLScraper\ScraperLib\Scraper.vb", +"region": { +"startLine": 290, +"startColumn": 35, +"endLine": 290, +"endColumn": 43 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Ember-MM\Addons\scraper.EmberCore.XML\XMLScraper\ScraperLib\Scraper.vb", +"region": { +"startLine": 511, +"startColumn": 34, +"endLine": 511, +"endColumn": 42 +} +} +} +] +} diff --git a/analyzers/its/expected/Nancy/Nancy--net452-S6566.json b/analyzers/its/expected/Nancy/Nancy--net452-S6566.json new file mode 100644 index 00000000000..f81f7e9cbe9 --- /dev/null +++ b/analyzers/its/expected/Nancy/Nancy--net452-S6566.json @@ -0,0 +1,69 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\Diagnostics\DiagnosticsHook.cs", +"region": { +"startLine": 169, +"startColumn": 106, +"endLine": 169, +"endColumn": 114 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\Diagnostics\DiagnosticsHook.cs", +"region": { +"startLine": 207, +"startColumn": 30, +"endLine": 207, +"endColumn": 38 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\Diagnostics\DiagnosticsHook.cs", +"region": { +"startLine": 283, +"startColumn": 26, +"endLine": 283, +"endColumn": 34 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\Json\Simple\NancySerializationStrategy.cs", +"region": { +"startLine": 208, +"startColumn": 28, +"endLine": 208, +"endColumn": 76 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\NancyEngine.cs", +"region": { +"startLine": 215, +"startColumn": 27, +"endLine": 215, +"endColumn": 35 +} +} +} +] +} diff --git a/analyzers/its/expected/Nancy/Nancy--netstandard2.0-S6566.json b/analyzers/its/expected/Nancy/Nancy--netstandard2.0-S6566.json new file mode 100644 index 00000000000..f81f7e9cbe9 --- /dev/null +++ b/analyzers/its/expected/Nancy/Nancy--netstandard2.0-S6566.json @@ -0,0 +1,69 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\Diagnostics\DiagnosticsHook.cs", +"region": { +"startLine": 169, +"startColumn": 106, +"endLine": 169, +"endColumn": 114 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\Diagnostics\DiagnosticsHook.cs", +"region": { +"startLine": 207, +"startColumn": 30, +"endLine": 207, +"endColumn": 38 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\Diagnostics\DiagnosticsHook.cs", +"region": { +"startLine": 283, +"startColumn": 26, +"endLine": 283, +"endColumn": 34 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\Json\Simple\NancySerializationStrategy.cs", +"region": { +"startLine": 208, +"startColumn": 28, +"endLine": 208, +"endColumn": 76 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy\NancyEngine.cs", +"region": { +"startLine": 215, +"startColumn": 27, +"endLine": 215, +"endColumn": 35 +} +} +} +] +} diff --git a/analyzers/its/expected/Nancy/Nancy.Authentication.Forms--net452-S6566.json b/analyzers/its/expected/Nancy/Nancy.Authentication.Forms--net452-S6566.json new file mode 100644 index 00000000000..2dada4391a8 --- /dev/null +++ b/analyzers/its/expected/Nancy/Nancy.Authentication.Forms--net452-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy.Authentication.Forms\FormsAuthentication.cs", +"region": { +"startLine": 301, +"startColumn": 120, +"endLine": 301, +"endColumn": 128 +} +} +} +] +} diff --git a/analyzers/its/expected/Nancy/Nancy.Authentication.Forms--netstandard2.0-S6566.json b/analyzers/its/expected/Nancy/Nancy.Authentication.Forms--netstandard2.0-S6566.json new file mode 100644 index 00000000000..2dada4391a8 --- /dev/null +++ b/analyzers/its/expected/Nancy/Nancy.Authentication.Forms--netstandard2.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy.Authentication.Forms\FormsAuthentication.cs", +"region": { +"startLine": 301, +"startColumn": 120, +"endLine": 301, +"endColumn": 128 +} +} +} +] +} diff --git a/analyzers/its/expected/Nancy/Nancy.ViewEngines.Spark--net452-S6566.json b/analyzers/its/expected/Nancy/Nancy.ViewEngines.Spark--net452-S6566.json new file mode 100644 index 00000000000..5ea59662015 --- /dev/null +++ b/analyzers/its/expected/Nancy/Nancy.ViewEngines.Spark--net452-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Nancy\src\Nancy.ViewEngines.Spark\NancyViewFolder.cs", +"region": { +"startLine": 242, +"startColumn": 40, +"endLine": 242, +"endColumn": 48 +} +} +} +] +} diff --git a/analyzers/its/expected/Net5/jsonserializerrecords-38409230-12D6-462B-BFAC-33B3491365B5-net5.0-S6566.json b/analyzers/its/expected/Net5/jsonserializerrecords-38409230-12D6-462B-BFAC-33B3491365B5-net5.0-S6566.json new file mode 100644 index 00000000000..0f0fb055b6b --- /dev/null +++ b/analyzers/its/expected/Net5/jsonserializerrecords-38409230-12D6-462B-BFAC-33B3491365B5-net5.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Net5\Net5Samples\JsonSerializerRecords\Program.cs", +"region": { +"startLine": 4, +"startColumn": 25, +"endLine": 4, +"endColumn": 33 +} +} +} +] +} diff --git a/analyzers/its/expected/Net5/recordswithstatichelper-541512C1-D79D-48B4-AE0B-D9A643E16D1F-net5.0-S6566.json b/analyzers/its/expected/Net5/recordswithstatichelper-541512C1-D79D-48B4-AE0B-D9A643E16D1F-net5.0-S6566.json new file mode 100644 index 00000000000..fd9847182c2 --- /dev/null +++ b/analyzers/its/expected/Net5/recordswithstatichelper-541512C1-D79D-48B4-AE0B-D9A643E16D1F-net5.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\Net5\Net5Samples\RecordWithStaticHelper\Program.cs", +"region": { +"startLine": 4, +"startColumn": 37, +"endLine": 4, +"endColumn": 45 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka--netstandard2.0-S6566.json new file mode 100644 index 00000000000..cec49ad7f0f --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka--netstandard2.0-S6566.json @@ -0,0 +1,238 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorSystem.cs", +"region": { +"startLine": 216, +"startColumn": 46, +"endLine": 216, +"endColumn": 54 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorSystem.cs", +"region": { +"startLine": 216, +"startColumn": 64, +"endLine": 216, +"endColumn": 115 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Dispatch\Mailbox.cs", +"region": { +"startLine": 535, +"startColumn": 70, +"endLine": 535, +"endColumn": 78 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Event\DeadLetterListener.cs", +"region": { +"startLine": 235, +"startColumn": 38, +"endLine": 235, +"endColumn": 46 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Event\DeadLetterListener.cs", +"region": { +"startLine": 240, +"startColumn": 40, +"endLine": 240, +"endColumn": 48 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Event\DeadLetterListener.cs", +"region": { +"startLine": 255, +"startColumn": 60, +"endLine": 255, +"endColumn": 68 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Event\DeadLetterListener.cs", +"region": { +"startLine": 276, +"startColumn": 56, +"endLine": 276, +"endColumn": 64 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Event\LogEvent.cs", +"region": { +"startLine": 51, +"startColumn": 25, +"endLine": 51, +"endColumn": 33 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\IO\SimpleDnsCache.cs", +"region": { +"startLine": 40, +"startColumn": 26, +"endLine": 40, +"endColumn": 34 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\IO\SimpleDnsCache.cs", +"region": { +"startLine": 59, +"startColumn": 23, +"endLine": 59, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Pattern\CircuitBreakerState.cs", +"region": { +"startLine": 40, +"startColumn": 30, +"endLine": 40, +"endColumn": 38 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Pattern\CircuitBreakerState.cs", +"region": { +"startLine": 94, +"startColumn": 23, +"endLine": 94, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\Extensions\DateTimeExtensions.cs", +"region": { +"startLine": 22, +"startColumn": 38, +"endLine": 22, +"endColumn": 62 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\Internal\AtomicState.cs", +"region": { +"startLine": 87, +"startColumn": 28, +"endLine": 87, +"endColumn": 36 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\Internal\AtomicState.cs", +"region": { +"startLine": 105, +"startColumn": 22, +"endLine": 105, +"endColumn": 30 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\Internal\AtomicState.cs", +"region": { +"startLine": 130, +"startColumn": 28, +"endLine": 130, +"endColumn": 36 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\Internal\AtomicState.cs", +"region": { +"startLine": 148, +"startColumn": 22, +"endLine": 148, +"endColumn": 30 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\TokenBucket.cs", +"region": { +"startLine": 139, +"startColumn": 45, +"endLine": 139, +"endColumn": 53 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S6566.json new file mode 100644 index 00000000000..2cef512655f --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S6566.json @@ -0,0 +1,147 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\ClusterHeartbeat.cs", +"region": { +"startLine": 85, +"startColumn": 30, +"endLine": 85, +"endColumn": 38 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\ClusterHeartbeat.cs", +"region": { +"startLine": 155, +"startColumn": 34, +"endLine": 155, +"endColumn": 42 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\ClusterHeartbeat.cs", +"region": { +"startLine": 241, +"startColumn": 23, +"endLine": 241, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\ClusterHeartbeat.cs", +"region": { +"startLine": 253, +"startColumn": 30, +"endLine": 253, +"endColumn": 38 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\SBR\SplitBrainResolver.cs", +"region": { +"startLine": 85, +"startColumn": 42, +"endLine": 85, +"endColumn": 50 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\SBR\SplitBrainResolver.cs", +"region": { +"startLine": 85, +"startColumn": 59, +"endLine": 85, +"endColumn": 67 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\SBR\SplitBrainResolver.cs", +"region": { +"startLine": 144, +"startColumn": 23, +"endLine": 144, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\SBR\SplitBrainResolver.cs", +"region": { +"startLine": 171, +"startColumn": 25, +"endLine": 171, +"endColumn": 33 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\SBR\SplitBrainResolver.cs", +"region": { +"startLine": 298, +"startColumn": 27, +"endLine": 298, +"endColumn": 35 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\SBR\SplitBrainResolver.cs", +"region": { +"startLine": 556, +"startColumn": 23, +"endLine": 556, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\SBR\SplitBrainResolver.cs", +"region": { +"startLine": 732, +"startColumn": 27, +"endLine": 732, +"endColumn": 35 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Cluster.Metrics--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Cluster.Metrics--netstandard2.0-S6566.json new file mode 100644 index 00000000000..c4c8ed78c22 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Cluster.Metrics--netstandard2.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.Cluster.Metrics\Collectors\DefaultCollector.cs", +"region": { +"startLine": 78, +"startColumn": 50, +"endLine": 78, +"endColumn": 58 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Cluster.Sharding--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Cluster.Sharding--netstandard2.0-S6566.json new file mode 100644 index 00000000000..2cfddb8c936 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Cluster.Sharding--netstandard2.0-S6566.json @@ -0,0 +1,43 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.Cluster.Sharding\PersistentShard.cs", +"region": { +"startLine": 125, +"startColumn": 77, +"endLine": 125, +"endColumn": 85 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.Cluster.Sharding\Shard.cs", +"region": { +"startLine": 832, +"startColumn": 85, +"endLine": 832, +"endColumn": 93 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.Cluster.Sharding\Shard.cs", +"region": { +"startLine": 839, +"startColumn": 28, +"endLine": 839, +"endColumn": 36 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Cluster.Tools--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Cluster.Tools--netstandard2.0-S6566.json new file mode 100644 index 00000000000..c949eb4b269 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Cluster.Tools--netstandard2.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.Cluster.Tools\PublishSubscribe\DistributedPubSubMediator.cs", +"region": { +"startLine": 639, +"startColumn": 27, +"endLine": 639, +"endColumn": 35 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.DistributedData--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.DistributedData--netstandard2.0-S6566.json new file mode 100644 index 00000000000..47e263bc1b8 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.DistributedData--netstandard2.0-S6566.json @@ -0,0 +1,199 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Internal\Internal.cs", +"region": { +"startLine": 481, +"startColumn": 31, +"endLine": 481, +"endColumn": 39 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\LWWRegister.cs", +"region": { +"startLine": 91, +"startColumn": 44, +"endLine": 91, +"endColumn": 52 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\LWWRegister.cs", +"region": { +"startLine": 98, +"startColumn": 45, +"endLine": 98, +"endColumn": 53 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Replicator.cs", +"region": { +"startLine": 383, +"startColumn": 34, +"endLine": 383, +"endColumn": 42 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Replicator.cs", +"region": { +"startLine": 416, +"startColumn": 30, +"endLine": 416, +"endColumn": 38 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Replicator.cs", +"region": { +"startLine": 474, +"startColumn": 26, +"endLine": 474, +"endColumn": 34 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Replicator.cs", +"region": { +"startLine": 1331, +"startColumn": 23, +"endLine": 1331, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Replicator.cs", +"region": { +"startLine": 1420, +"startColumn": 58, +"endLine": 1420, +"endColumn": 66 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Replicator.cs", +"region": { +"startLine": 1421, +"startColumn": 65, +"endLine": 1421, +"endColumn": 73 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Replicator.cs", +"region": { +"startLine": 1450, +"startColumn": 31, +"endLine": 1450, +"endColumn": 39 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Serialization\ReplicatorMessageSerializer.cs", +"region": { +"startLine": 53, +"startColumn": 29, +"endLine": 53, +"endColumn": 37 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Serialization\ReplicatorMessageSerializer.cs", +"region": { +"startLine": 74, +"startColumn": 29, +"endLine": 74, +"endColumn": 37 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Serialization\ReplicatorMessageSerializer.cs", +"region": { +"startLine": 108, +"startColumn": 21, +"endLine": 108, +"endColumn": 29 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Serialization\ReplicatorMessageSerializer.cs", +"region": { +"startLine": 117, +"startColumn": 29, +"endLine": 117, +"endColumn": 37 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.DistributedData\Serialization\ReplicatorMessageSerializer.cs", +"region": { +"startLine": 578, +"startColumn": 67, +"endLine": 578, +"endColumn": 99 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--net471-S6566.json b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--net471-S6566.json new file mode 100644 index 00000000000..adcb12a6ac7 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--net471-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner\Program.cs", +"region": { +"startLine": 476, +"startColumn": 23, +"endLine": 476, +"endColumn": 31 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--net5.0-S6566.json b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--net5.0-S6566.json new file mode 100644 index 00000000000..adcb12a6ac7 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--net5.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner\Program.cs", +"region": { +"startLine": 476, +"startColumn": 23, +"endLine": 476, +"endColumn": 31 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--netcoreapp3.1-S6566.json b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--netcoreapp3.1-S6566.json new file mode 100644 index 00000000000..adcb12a6ac7 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner--netcoreapp3.1-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner\Program.cs", +"region": { +"startLine": 476, +"startColumn": 23, +"endLine": 476, +"endColumn": 31 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner.Shared--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner.Shared--netstandard2.0-S6566.json new file mode 100644 index 00000000000..c77104fa3cb --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner.Shared--netstandard2.0-S6566.json @@ -0,0 +1,576 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Persistence\FileNameGenerator.cs", +"region": { +"startLine": 17, +"startColumn": 76, +"endLine": 17, +"endColumn": 84 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Persistence\TimelineItemFactory.cs", +"region": { +"startLine": 38, +"startColumn": 73, +"endLine": 38, +"endColumn": 101 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Persistence\TimelineItemFactory.cs", +"region": { +"startLine": 48, +"startColumn": 84, +"endLine": 48, +"endColumn": 112 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Persistence\VisualizerRuntimeTemplate.Tree.cs", +"region": { +"startLine": 100, +"startColumn": 38, +"endLine": 100, +"endColumn": 71 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Persistence\VisualizerRuntimeTemplate.Tree.cs", +"region": { +"startLine": 101, +"startColumn": 38, +"endLine": 101, +"endColumn": 70 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunCoordinator.cs", +"region": { +"startLine": 61, +"startColumn": 44, +"endLine": 61, +"endColumn": 52 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunCoordinator.cs", +"region": { +"startLine": 89, +"startColumn": 95, +"endLine": 89, +"endColumn": 103 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 61, +"startColumn": 45, +"endLine": 61, +"endColumn": 72 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 61, +"startColumn": 75, +"endLine": 61, +"endColumn": 83 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 61, +"startColumn": 94, +"endLine": 61, +"endColumn": 117 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 76, +"startColumn": 27, +"endLine": 76, +"endColumn": 35 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 143, +"startColumn": 30, +"endLine": 143, +"endColumn": 38 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 196, +"startColumn": 45, +"endLine": 196, +"endColumn": 72 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 196, +"startColumn": 75, +"endLine": 196, +"endColumn": 83 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 196, +"startColumn": 94, +"endLine": 196, +"endColumn": 117 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 206, +"startColumn": 27, +"endLine": 206, +"endColumn": 35 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 287, +"startColumn": 85, +"endLine": 287, +"endColumn": 93 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 350, +"startColumn": 45, +"endLine": 350, +"endColumn": 72 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 350, +"startColumn": 75, +"endLine": 350, +"endColumn": 83 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 350, +"startColumn": 94, +"endLine": 350, +"endColumn": 117 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 372, +"startColumn": 27, +"endLine": 372, +"endColumn": 35 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\ConsoleMessageSinkActor.cs", +"region": { +"startLine": 42, +"startColumn": 63, +"endLine": 42, +"endColumn": 109 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\ConsoleMessageSinkActor.cs", +"region": { +"startLine": 49, +"startColumn": 17, +"endLine": 49, +"endColumn": 102 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\ConsoleMessageSinkActor.cs", +"region": { +"startLine": 49, +"startColumn": 61, +"endLine": 49, +"endColumn": 69 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\ConsoleMessageSinkActor.cs", +"region": { +"startLine": 143, +"startColumn": 53, +"endLine": 143, +"endColumn": 61 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\ConsoleMessageSinkActor.cs", +"region": { +"startLine": 150, +"startColumn": 92, +"endLine": 150, +"endColumn": 100 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\ConsoleMessageSinkActor.cs", +"region": { +"startLine": 157, +"startColumn": 92, +"endLine": 157, +"endColumn": 100 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\MessageSink.cs", +"region": { +"startLine": 145, +"startColumn": 86, +"endLine": 145, +"endColumn": 94 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\MessageSink.cs", +"region": { +"startLine": 164, +"startColumn": 73, +"endLine": 164, +"endColumn": 81 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\MessageSink.cs", +"region": { +"startLine": 239, +"startColumn": 82, +"endLine": 239, +"endColumn": 90 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\Spec.cs", +"region": { +"startLine": 31, +"startColumn": 25, +"endLine": 31, +"endColumn": 33 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\TeamCityMessageSinkActor.cs", +"region": { +"startLine": 76, +"startColumn": 73, +"endLine": 76, +"endColumn": 81 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\TeamCityMessageSinkActor.cs", +"region": { +"startLine": 86, +"startColumn": 67, +"endLine": 86, +"endColumn": 75 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\TestCoordinatorEnabledMessageSink.cs", +"region": { +"startLine": 98, +"startColumn": 62, +"endLine": 98, +"endColumn": 70 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\TestCoordinatorEnabledMessageSink.cs", +"region": { +"startLine": 109, +"startColumn": 62, +"endLine": 109, +"endColumn": 70 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Sinks\TimelineLogCollectorActor.cs", +"region": { +"startLine": 100, +"startColumn": 24, +"endLine": 100, +"endColumn": 32 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\TrxReporter\Models\Times.cs", +"region": { +"startLine": 18, +"startColumn": 23, +"endLine": 18, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\TrxReporter\Models\UnitTestResult.cs", +"region": { +"startLine": 26, +"startColumn": 23, +"endLine": 26, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\TrxReporter\SpecSession.cs", +"region": { +"startLine": 26, +"startColumn": 88, +"endLine": 26, +"endColumn": 96 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\TrxReporter\SpecSession.cs", +"region": { +"startLine": 27, +"startColumn": 129, +"endLine": 27, +"endColumn": 137 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\TrxReporter\SpecSession.cs", +"region": { +"startLine": 28, +"startColumn": 119, +"endLine": 28, +"endColumn": 127 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\TrxReporter\SpecSession.cs", +"region": { +"startLine": 29, +"startColumn": 122, +"endLine": 29, +"endColumn": 130 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\TrxReporter\SpecSession.cs", +"region": { +"startLine": 30, +"startColumn": 74, +"endLine": 30, +"endColumn": 82 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\TrxReporter\TrxSinkActor.cs", +"region": { +"startLine": 102, +"startColumn": 77, +"endLine": 102, +"endColumn": 85 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S6566.json new file mode 100644 index 00000000000..31bce215e1e --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S6566.json @@ -0,0 +1,212 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\AtLeastOnceDeliverySemantic.cs", +"region": { +"startLine": 408, +"startColumn": 43, +"endLine": 408, +"endColumn": 51 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\AtLeastOnceDeliverySemantic.cs", +"region": { +"startLine": 408, +"startColumn": 81, +"endLine": 408, +"endColumn": 89 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\AtLeastOnceDeliverySemantic.cs", +"region": { +"startLine": 437, +"startColumn": 28, +"endLine": 437, +"endColumn": 36 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\AtLeastOnceDeliverySemantic.cs", +"region": { +"startLine": 501, +"startColumn": 23, +"endLine": 501, +"endColumn": 31 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Snapshot\LocalSnapshotStore.cs", +"region": { +"startLine": 295, +"startColumn": 66, +"endLine": 295, +"endColumn": 85 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Snapshot\MemorySnapshotStore.cs", +"region": { +"startLine": 31, +"startColumn": 111, +"endLine": 31, +"endColumn": 119 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Snapshot\MemorySnapshotStore.cs", +"region": { +"startLine": 31, +"startColumn": 154, +"endLine": 31, +"endColumn": 162 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Snapshot\MemorySnapshotStore.cs", +"region": { +"startLine": 85, +"startColumn": 39, +"endLine": 85, +"endColumn": 47 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Snapshot\MemorySnapshotStore.cs", +"region": { +"startLine": 85, +"startColumn": 85, +"endLine": 85, +"endColumn": 93 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Snapshot\MemorySnapshotStore.cs", +"region": { +"startLine": 102, +"startColumn": 101, +"endLine": 102, +"endColumn": 130 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Snapshot\SnapshotStore.cs", +"region": { +"startLine": 78, +"startColumn": 124, +"endLine": 78, +"endColumn": 132 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\SnapshotProtocol.cs", +"region": { +"startLine": 62, +"startColumn": 56, +"endLine": 62, +"endColumn": 64 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\SnapshotProtocol.cs", +"region": { +"startLine": 481, +"startColumn": 112, +"endLine": 481, +"endColumn": 120 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\SnapshotProtocol.cs", +"region": { +"startLine": 486, +"startColumn": 99, +"endLine": 486, +"endColumn": 107 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\SnapshotProtocol.cs", +"region": { +"startLine": 501, +"startColumn": 44, +"endLine": 501, +"endColumn": 52 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\SnapshotProtocol.cs", +"region": { +"startLine": 508, +"startColumn": 84, +"endLine": 508, +"endColumn": 92 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S6566.json new file mode 100644 index 00000000000..79b51d8084b --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S6566.json @@ -0,0 +1,56 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Journal\BatchingSqlJournal.cs", +"region": { +"startLine": 1279, +"startColumn": 66, +"endLine": 1279, +"endColumn": 74 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Journal\ITimestampProvider.cs", +"region": { +"startLine": 35, +"startColumn": 77, +"endLine": 35, +"endColumn": 85 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Journal\QueryExecutor.cs", +"region": { +"startLine": 687, +"startColumn": 59, +"endLine": 687, +"endColumn": 67 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Snapshot\SqlSnapshotStore.cs", +"region": { +"startLine": 203, +"startColumn": 61, +"endLine": 203, +"endColumn": 69 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Persistence.Sqlite--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Persistence.Sqlite--netstandard2.0-S6566.json new file mode 100644 index 00000000000..9a274f58dfa --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Persistence.Sqlite--netstandard2.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sqlite\Snapshot\SqliteSnapshotStore.cs", +"region": { +"startLine": 88, +"startColumn": 29, +"endLine": 88, +"endColumn": 61 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Persistence.TCK--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Persistence.TCK--netstandard2.0-S6566.json new file mode 100644 index 00000000000..547c1094921 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Persistence.TCK--netstandard2.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence.TCK\Snapshot\SnapshotStoreSpec.cs", +"region": { +"startLine": 119, +"startColumn": 99, +"endLine": 119, +"endColumn": 119 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Remote--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Remote--netstandard2.0-S6566.json new file mode 100644 index 00000000000..5b44f7871db --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Remote--netstandard2.0-S6566.json @@ -0,0 +1,56 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote\Deadline.cs", +"region": { +"startLine": 31, +"startColumn": 26, +"endLine": 31, +"endColumn": 34 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote\Deadline.cs", +"region": { +"startLine": 39, +"startColumn": 26, +"endLine": 39, +"endColumn": 34 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote\Deadline.cs", +"region": { +"startLine": 55, +"startColumn": 56, +"endLine": 55, +"endColumn": 64 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote\Deadline.cs", +"region": { +"startLine": 89, +"startColumn": 37, +"endLine": 89, +"endColumn": 45 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Streams--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Streams--netstandard2.0-S6566.json new file mode 100644 index 00000000000..b592a81b2ef --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Streams--netstandard2.0-S6566.json @@ -0,0 +1,251 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\Restart.cs", +"region": { +"startLine": 603, +"startColumn": 47, +"endLine": 603, +"endColumn": 55 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\Restart.cs", +"region": { +"startLine": 605, +"startColumn": 65, +"endLine": 605, +"endColumn": 73 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Extra\Timed.cs", +"region": { +"startLine": 296, +"startColumn": 36, +"endLine": 296, +"endColumn": 44 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Fusing\Ops.cs", +"region": { +"startLine": 3237, +"startColumn": 90, +"endLine": 3237, +"endColumn": 98 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Fusing\Ops.cs", +"region": { +"startLine": 3267, +"startColumn": 34, +"endLine": 3267, +"endColumn": 42 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 212, +"startColumn": 33, +"endLine": 212, +"endColumn": 41 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 220, +"startColumn": 33, +"endLine": 220, +"endColumn": 41 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 234, +"startColumn": 37, +"endLine": 234, +"endColumn": 45 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 295, +"startColumn": 33, +"endLine": 295, +"endColumn": 41 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 304, +"startColumn": 33, +"endLine": 304, +"endColumn": 41 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 322, +"startColumn": 56, +"endLine": 322, +"endColumn": 64 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 383, +"startColumn": 33, +"endLine": 383, +"endColumn": 41 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 416, +"startColumn": 37, +"endLine": 416, +"endColumn": 45 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 423, +"startColumn": 58, +"endLine": 423, +"endColumn": 66 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 589, +"startColumn": 33, +"endLine": 589, +"endColumn": 41 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 597, +"startColumn": 33, +"endLine": 597, +"endColumn": 41 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 626, +"startColumn": 32, +"endLine": 626, +"endColumn": 40 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 641, +"startColumn": 28, +"endLine": 641, +"endColumn": 36 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Timers.cs", +"region": { +"startLine": 645, +"startColumn": 37, +"endLine": 645, +"endColumn": 45 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Streams.TestKit--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.Streams.TestKit--netstandard2.0-S6566.json new file mode 100644 index 00000000000..36b3a3b878c --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Streams.TestKit--netstandard2.0-S6566.json @@ -0,0 +1,30 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams.TestKit\TestSubscriber.cs", +"region": { +"startLine": 490, +"startColumn": 32, +"endLine": 490, +"endColumn": 40 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams.TestKit\TestSubscriber.cs", +"region": { +"startLine": 498, +"startColumn": 86, +"endLine": 498, +"endColumn": 94 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.TestKit--netstandard2.0-S6566.json b/analyzers/its/expected/akka.net/Akka.TestKit--netstandard2.0-S6566.json new file mode 100644 index 00000000000..e6e9a79b496 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.TestKit--netstandard2.0-S6566.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.TestKit\TestKitBase.cs", +"region": { +"startLine": 235, +"startColumn": 70, +"endLine": 235, +"endColumn": 78 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Tests.Performance--netcoreapp3.1-S6566.json b/analyzers/its/expected/akka.net/Akka.Tests.Performance--netcoreapp3.1-S6566.json new file mode 100644 index 00000000000..64d3e5f4198 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Tests.Performance--netcoreapp3.1-S6566.json @@ -0,0 +1,30 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Tests.Performance\IO\TcpHorizontalScaleSpec.cs", +"region": { +"startLine": 147, +"startColumn": 27, +"endLine": 147, +"endColumn": 35 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\core\Akka.Tests.Performance\IO\TcpHorizontalScaleSpec.cs", +"region": { +"startLine": 148, +"startColumn": 20, +"endLine": 148, +"endColumn": 28 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/PersistenceBenchmark--net471-S6566.json b/analyzers/its/expected/akka.net/PersistenceBenchmark--net471-S6566.json new file mode 100644 index 00000000000..14ef11c69cd --- /dev/null +++ b/analyzers/its/expected/akka.net/PersistenceBenchmark--net471-S6566.json @@ -0,0 +1,30 @@ +{ +"issues": [ +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\benchmark\PersistenceBenchmark\Messages.cs", +"region": { +"startLine": 49, +"startColumn": 25, +"endLine": 49, +"endColumn": 33 +} +} +}, +{ +"id": "S6566", +"message": "Prefer using "DateTimeOffset" instead of "DateTime"", +"location": { +"uri": "sources\akka.net\src\benchmark\PersistenceBenchmark\Messages.cs", +"region": { +"startLine": 54, +"startColumn": 25, +"endLine": 54, +"endColumn": 33 +} +} +} +] +} diff --git a/analyzers/rspec/cs/S6566.html b/analyzers/rspec/cs/S6566.html new file mode 100644 index 00000000000..1063789052f --- /dev/null +++ b/analyzers/rspec/cs/S6566.html @@ -0,0 +1,48 @@ +

This rule recommends using DateTimeOffset instead of DateTime for projects targeting .NET Framework 2.0 or later.

+

Why is this an issue?

+

You should use DateTimeOffset instead of DateTime as it provides all the information that the DateTime +struct has, and additionally, the offset from Coordinated Universal Time (UTC). This way you can avoid potential problems created by the lack of +timezone awareness (see the "Pitfalls" section below for more information).

+

However, it’s important to note that although DateTimeOffset contains more information than DateTime by storing the +offset to UTC, it isn’t tied to a specific time zone. This information must be stored separately to have a full picture of the moment in time with the +use of TimeZoneInfo.

+

How to fix it

+

In most cases, you can directly replace DateTime with DateTimeOffset. When hardcoding dates with local kind, remember +that the offset is timezone dependent, so it should be set according to which timezone that data represents. For more information, refer to +DateTime and DateTimeOffset documentation from Microsoft (see the "Resources" section below).

+

Code examples

+

Noncompliant code example

+
+DateTime myDate = new DateTime(2008, 6, 19, 7, 0, 0, DateTimeKind.Local); // Noncompliant
+
+var now = DateTime.Now; // Noncompliant
+
+

Compliant solution

+
+DateTimeOffset myDate = new DateTimeOffset(2008, 6, 19, 7, 0, 0, TimeSpan.FromHours(-7)); // Compliant
+
+var now = DateTimeOffset.Now; // Compliant
+
+

Pitfalls

+

Common DateTime pitfalls include:

+ +

Resources

+

Documentation

+ + diff --git a/analyzers/rspec/cs/S6566.json b/analyzers/rspec/cs/S6566.json new file mode 100644 index 00000000000..5f287470c83 --- /dev/null +++ b/analyzers/rspec/cs/S6566.json @@ -0,0 +1,15 @@ +{ + "title": "Use \"DateTimeOffset\" instead of \"DateTime\"", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "10min" + }, + "tags": [], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-6566", + "sqKey": "S6566", + "scope": "All", + "quickfix": "infeasible" +} diff --git a/analyzers/rspec/vbnet/S6566.html b/analyzers/rspec/vbnet/S6566.html new file mode 100644 index 00000000000..c67997f35a7 --- /dev/null +++ b/analyzers/rspec/vbnet/S6566.html @@ -0,0 +1,48 @@ +

This rule recommends using DateTimeOffset instead of DateTime for projects targeting .NET Framework 2.0 or later.

+

Why is this an issue?

+

You should use DateTimeOffset instead of DateTime as it provides all the information that the DateTime +struct has, and additionally, the offset from Coordinated Universal Time (UTC). This way you can avoid potential problems created by the lack of +timezone awareness (see the "Pitfalls" section below for more information).

+

However, it’s important to note that although DateTimeOffset contains more information than DateTime by storing the +offset to UTC, it isn’t tied to a specific time zone. This information must be stored separately to have a full picture of the moment in time with the +use of TimeZoneInfo.

+

How to fix it

+

In most cases, you can directly replace DateTime with DateTimeOffset. When hardcoding dates with local kind, remember +that the offset is timezone dependent, so it should be set according to which timezone that data represents. For more information, refer to +DateTime and DateTimeOffset documentation from Microsoft (see the "Resources" section below).

+

Code examples

+

Noncompliant code example

+
+Dim myDate As DateTime = New DateTime(2008, 6, 19, 7, 0, 0, DateTimeKind.Local) ' Noncompliant
+
+Dim now = DateTime.Now ' Noncompliant
+
+

Compliant solution

+
+Dim myDate As DateTimeOffset = New DateTimeOffset(2008, 6, 19, 7, 0, 0, TimeSpan.FromHours(-7)) ' Compliant
+
+Dim now = DateTimeOffset.Now ' Compliant
+
+

Pitfalls

+

Common DateTime pitfalls include:

+ +

Resources

+

Documentation

+ + diff --git a/analyzers/rspec/vbnet/S6566.json b/analyzers/rspec/vbnet/S6566.json new file mode 100644 index 00000000000..5f287470c83 --- /dev/null +++ b/analyzers/rspec/vbnet/S6566.json @@ -0,0 +1,15 @@ +{ + "title": "Use \"DateTimeOffset\" instead of \"DateTime\"", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "10min" + }, + "tags": [], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-6566", + "sqKey": "S6566", + "scope": "All", + "quickfix": "infeasible" +} diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseDateTimeInsteadOfDateTimeOffset.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseDateTimeInsteadOfDateTimeOffset.cs new file mode 100644 index 00000000000..e09a1fb30d7 --- /dev/null +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseDateTimeInsteadOfDateTimeOffset.cs @@ -0,0 +1,29 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +namespace SonarAnalyzer.Rules.CSharp; + +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class UseDateTimeInsteadOfDateTimeOffset : UseDateTimeInsteadOfDateTimeOffsetBase +{ + protected override ILanguageFacade Language => CSharpFacade.Instance; + + protected override string[] ValidNames { get; } = new[] { "DateTime" }; +} diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/UseDateTimeInsteadOfDateTimeOffsetBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/UseDateTimeInsteadOfDateTimeOffsetBase.cs new file mode 100644 index 00000000000..b323caaa84d --- /dev/null +++ b/analyzers/src/SonarAnalyzer.Common/Rules/UseDateTimeInsteadOfDateTimeOffsetBase.cs @@ -0,0 +1,81 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +namespace SonarAnalyzer.Rules; + +public abstract class UseDateTimeInsteadOfDateTimeOffsetBase : SonarDiagnosticAnalyzer + where TSyntaxKind : struct +{ + private const string DiagnosticId = "S6566"; + + protected override string MessageFormat => "Prefer using \"DateTimeOffset\" instead of \"DateTime\""; + + private static readonly ImmutableArray TargetMemberAccess = ImmutableArray.Create( + nameof(DateTime.MaxValue), + nameof(DateTime.MinValue), + nameof(DateTime.Now), + nameof(DateTime.Today), + nameof(DateTime.UtcNow), + "UnixEpoch"); + + protected abstract string[] ValidNames { get; } + + protected UseDateTimeInsteadOfDateTimeOffsetBase() : base(DiagnosticId) { } + + protected sealed override void Initialize(SonarAnalysisContext context) + { + context.RegisterNodeAction( + Language.GeneratedCodeRecognizer, + c => + { + if ((c.Node.RawKind == (int)SyntaxKindEx.ImplicitObjectCreationExpression || IsNamedDateTime(GetTypeName(c.Node))) + && IsDateTimeType(c.Node, c.SemanticModel)) + { + c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation())); + } + }, + Language.SyntaxKind.ObjectCreationExpressions); + + context.RegisterNodeAction( + Language.GeneratedCodeRecognizer, + c => + { + if (Language.Syntax.NodeExpression(c.Node) is var expression + && IsNamedDateTime(Language.GetName(expression)) + && TargetMemberAccess.Contains(Language.GetName(c.Node)) + && IsDateTimeType(expression, c.SemanticModel)) + { + c.ReportIssue(Diagnostic.Create(Rule, Language.Syntax.NodeExpression(c.Node).GetLocation())); + } + }, + Language.SyntaxKind.SimpleMemberAccessExpression); + } + + private static bool IsDateTimeType(SyntaxNode node, SemanticModel model) => + model.GetTypeInfo(node).Type.Is(KnownType.System_DateTime); + + private bool IsNamedDateTime(string name) => + Array.Exists(ValidNames, x => x.Equals(name, Language.NameComparison)); + + private string GetTypeName(SyntaxNode node) => + Language.Syntax.ObjectCreationTypeIdentifier(node) is { IsMissing: false } identifier + ? identifier.ValueText + : string.Empty; +} diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UseDateTimeInsteadOfDateTimeOffset.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UseDateTimeInsteadOfDateTimeOffset.cs new file mode 100644 index 00000000000..77490a53bcd --- /dev/null +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UseDateTimeInsteadOfDateTimeOffset.cs @@ -0,0 +1,29 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +namespace SonarAnalyzer.Rules.VisualBasic; + +[DiagnosticAnalyzer(LanguageNames.VisualBasic)] +public sealed class UseDateTimeInsteadOfDateTimeOffset : UseDateTimeInsteadOfDateTimeOffsetBase +{ + protected override ILanguageFacade Language => VisualBasicFacade.Instance; + + protected override string[] ValidNames { get; } = new[] { "DateTime", "Date" }; +} diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingCS.cs b/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingCS.cs index 55d3821c13d..f7acb032eb6 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingCS.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingCS.cs @@ -6490,7 +6490,7 @@ internal static class RuleTypeMappingCS // ["S6563"], // ["S6564"], // ["S6565"], - // ["S6566"], + ["S6566"] = "CODE_SMELL", // ["S6567"], // ["S6568"], // ["S6569"], diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingVB.cs b/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingVB.cs index 7687765a04c..066e8d583c6 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingVB.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingVB.cs @@ -6490,7 +6490,7 @@ internal static class RuleTypeMappingVB // ["S6563"], // ["S6564"], // ["S6565"], - // ["S6566"], + ["S6566"] = "CODE_SMELL", // ["S6567"], // ["S6568"], // ["S6569"], diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/UseDateTimeInsteadOfDateTimeOffsetTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/UseDateTimeInsteadOfDateTimeOffsetTest.cs new file mode 100644 index 00000000000..5813e0d475f --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/UseDateTimeInsteadOfDateTimeOffsetTest.cs @@ -0,0 +1,51 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using CS = SonarAnalyzer.Rules.CSharp; +using VB = SonarAnalyzer.Rules.VisualBasic; + +namespace SonarAnalyzer.UnitTest.Rules; + +[TestClass] +public class UseDateTimeInsteadOfDateTimeOffsetTest +{ + private readonly VerifierBuilder builderCS = new VerifierBuilder(); + private readonly VerifierBuilder builderVB = new VerifierBuilder(); + + [TestMethod] + public void UseDateTimeInsteadOfDateTimeOffset_CS() => + builderCS.AddPaths("UseDateTimeInsteadOfDateTimeOffset.cs").Verify(); + +#if NET + + [TestMethod] + public void UseDateTimeInsteadOfDateTimeOffset_CSharp9() => + builderCS.AddPaths("UseDateTimeInsteadOfDateTimeOffset.CSharp9.cs").WithTopLevelStatements().Verify(); + + [TestMethod] + public void UseDateTimeInsteadOfDateTimeOffset_VB_Net() => + builderVB.AddPaths("UseDateTimeInsteadOfDateTimeOffset.Net.vb").Verify(); + +#endif + + [TestMethod] + public void UseDateTimeInsteadOfDateTimeOffset_VB() => + builderVB.AddPaths("UseDateTimeInsteadOfDateTimeOffset.vb").Verify(); +} diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.CSharp9.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.CSharp9.cs new file mode 100644 index 00000000000..58d4988bedc --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.CSharp9.cs @@ -0,0 +1,13 @@ +using System; +using System.Globalization; + +DateTime myDate = new(1); // Noncompliant {{Prefer using "DateTimeOffset" instead of "DateTime"}} +// ^^^^^^ +_ = new DateTime(1, 1, 1, 1, 1, 1, 1, 1, new GregorianCalendar()); // Noncompliant +_ = new DateTime(1, 1, 1, 1, 1, 1, 1, 1, DateTimeKind.Utc); // Noncompliant +_ = new DateTime(1, 1, 1, 1, 1, 1, 1, 1, new GregorianCalendar(), DateTimeKind.Utc); // Noncompliant + +_ = DateTime.UnixEpoch; // Noncompliant +Span span = new(); +myDate.TryFormat(span, out int myInt); +myDate.AddMicroseconds(0); diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.Net.vb b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.Net.vb new file mode 100644 index 00000000000..01b12edd60c --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.Net.vb @@ -0,0 +1,20 @@ +Imports System +Imports System.Globalization + +Public Class Program + Private Sub Constructors() + Dim a = New DateTime(1, 1, 1, 1, 1, 1, 1, 1, New GregorianCalendar()) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1, 1, 1, DateTimeKind.Utc) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1, 1, 1, New GregorianCalendar(), DateTimeKind.Utc) ' Noncompliant + End Sub + + Private Sub Fields([date] As Date) + Dim a = Date.UnixEpoch ' Noncompliant + Dim b = [date].Microsecond + Dim c = [date].Nanosecond + End Sub + + Private Sub Methods([date] As Date) + [date].AddMicroseconds(0) + End Sub +End Class diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.cs new file mode 100644 index 00000000000..d68670c5d14 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.cs @@ -0,0 +1,98 @@ +using System; +using System.Globalization; +using MyAlias = System.DateTime; + +public class Program +{ + void Constructors() + { + _ = new DateTime(1); // Noncompliant {{Prefer using "DateTimeOffset" instead of "DateTime"}} +// ^^^^^^^^^^^^^^^ + _ = new DateTime(1, 1, 1); // Noncompliant + _ = new DateTime(1, 1, 1, new GregorianCalendar()); // Noncompliant + _ = new DateTime(1, 1, 1, 1, 1, 1); // Noncompliant + _ = new DateTime(1, 1, 1, 1, 1, 1, new GregorianCalendar()); // Noncompliant + _ = new DateTime(1, 1, 1, 1, 1, 1, DateTimeKind.Utc); // Noncompliant + _ = new DateTime(1, 1, 1, 1, 1, 1, 1); // Noncompliant + _ = new DateTime(1, 1, 1, 1, 1, 1, 1, new GregorianCalendar()); // Noncompliant + _ = new DateTime(1, 1, 1, 1, 1, 1, 1, DateTimeKind.Utc); // Noncompliant + _ = new DateTime(1, 1, 1, 1, 1, 1, 1, new GregorianCalendar(), DateTimeKind.Utc); // Noncompliant + _ = new MyAlias(1); // FN + _ = new System.DateTime(1); // Noncompliant + } + + void Fields() + { + _ = DateTime.MaxValue; // Noncompliant +// ^^^^^^^^ + _ = DateTime.MinValue; // Noncompliant + } + + void StaticProperties() + { + _ = DateTime.Now; // Noncompliant +// ^^^^^^^^ + _ = DateTime.Today; // Noncompliant + _ = DateTime.UtcNow; // Noncompliant + } + + void Methods(DateTime date) + { + date.Add(TimeSpan.Zero); + date.AddDays(0); + date.AddHours(0); + date.AddMilliseconds(0); + date.AddMinutes(0); + date.AddMonths(0); + date.AddSeconds(0); + date.AddTicks(0); + date.AddYears(0); + date.CompareTo(date); + DateTime.Compare(date, date); + DateTime.DaysInMonth(1, 1); + DateTime.Equals(date, date); + date.Equals(date); + DateTime.FromBinary(1); + DateTime.FromFileTime(1); + DateTime.FromFileTimeUtc(1); + DateTime.FromOADate(1); + date.GetDateTimeFormats('a'); + date.GetHashCode(); + date.GetTypeCode(); + date.IsDaylightSavingTime(); + DateTime.IsLeapYear(1); + DateTime.Parse("06/01/1993"); + DateTime.ParseExact("06/01/1993", "dd/MM/yyyy", null); + DateTime.SpecifyKind(date, DateTimeKind.Local); + date.Subtract(date); + date.ToBinary(); + date.ToFileTime(); + date.ToFileTimeUtc(); + date.ToLocalTime(); + date.ToLongDateString(); + date.ToLongTimeString(); + date.ToShortDateString(); + date.ToShortTimeString(); + date.ToString(); + date.ToUniversalTime(); + DateTime.TryParse("06/01/1993", out date); + DateTime.TryParseExact("06/01/1993", "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out date); + } + + void EdgeCases() + { + var a = DateTime.Now.AddDays(-1).Ticks; // Noncompliant + var b = new DateTimeOffset(DateTime.Now); // Noncompliant + var typeName = nameof(DateTime); // Compliant + } +} + +public class FakeDateTime +{ + void MyMethod() => new DateTime(1); // Compliant + + public class DateTime + { + public DateTime(int ticks) { } + } +} diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.vb b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.vb new file mode 100644 index 00000000000..9312541e23c --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseDateTimeInsteadOfDateTimeOffset.vb @@ -0,0 +1,96 @@ +Imports System +Imports System.Globalization +Imports MyAlias = System.DateTime + +Public Class Program + Private Sub Constructors() + Dim a = New DateTime(1) ' Noncompliant {{Prefer using "DateTimeOffset" instead of "DateTime"}} +' ^^^^^^^^^^^^^^^ + a = New DateTime(1, 1, 1) ' Noncompliant + a = New DateTime(1, 1, 1, New GregorianCalendar()) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1, New GregorianCalendar()) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1, DateTimeKind.Utc) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1, 1) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1, 1, New GregorianCalendar()) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1, 1, DateTimeKind.Utc) ' Noncompliant + a = New DateTime(1, 1, 1, 1, 1, 1, 1, New GregorianCalendar(), DateTimeKind.Utc) ' Noncompliant + a = New Date(1, 1, 1, 1, 1, 1, 1, New GregorianCalendar(), DateTimeKind.Utc) ' Noncompliant + a = New DateTime(1) ' Noncompliant + a = New MyAlias(1) ' FN + a = New System.DateTime(1) ' Noncompliant + End Sub + + Private Sub Fields() + Dim a = Date.MaxValue ' Noncompliant +' ^^^^ + a = Date.MinValue ' Noncompliant + a = DateTime.MinValue ' Noncompliant + End Sub + + Private Sub Properties([date] As Date) + Dim a = [date].Date + Dim b = [date].Day + Dim c = [date].DayOfWeek + Dim d = [date].DayOfYear + Dim e = [date].Hour + Dim f = [date].Kind + Dim g = [date].Millisecond + Dim h = [date].Minute + Dim i = [date].Month + Dim l = [date].Second + Dim m = [date].Ticks + Dim n = [date].TimeOfDay + Dim o = [date].Year + End Sub + + Private Sub StaticProperties() + Dim a = Date.Now ' Noncompliant +' ^^^^ + a = Date.Today ' Noncompliant + a = Date.UtcNow ' Noncompliant + End Sub + + Private Sub Methods([date] As Date) + [date].Add(TimeSpan.Zero) + [date].AddDays(0) + [date].AddHours(0) + [date].AddMilliseconds(0) + [date].AddMinutes(0) + [date].AddMonths(0) + [date].AddSeconds(0) + [date].AddTicks(0) + [date].AddYears(0) + [date].CompareTo([date]) + Date.Compare([date], [date]) + Date.DaysInMonth(1, 1) + Date.Equals([date], [date]) + [date].Equals([date]) + Date.FromBinary(1) + Date.FromFileTime(1) + Date.FromFileTimeUtc(1) + Date.FromOADate(1) + [date].GetDateTimeFormats("a"c) + [date].GetHashCode() + [date].GetTypeCode() + [date].IsDaylightSavingTime() + Date.IsLeapYear(1) + Date.Parse("06/01/1993") + Date.ParseExact("06/01/1993", "dd/MM/yyyy", Nothing) + Date.SpecifyKind([date], DateTimeKind.Local) + [date].Subtract([date]) + [date].ToBinary() + [date].ToFileTime() + [date].ToFileTimeUtc() + [date].ToLocalTime() + [date].ToLongDateString() + [date].ToLongTimeString() + [date].ToShortDateString() + [date].ToShortTimeString() + [date].ToString() + [date].ToUniversalTime() + Dim myInt As Integer = Nothing + Date.TryParse("06/01/1993", [date]) + Date.TryParseExact("06/01/1993", "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, [date]) + End Sub +End Class