From 42043f117a0021c6de5680ed81bcc7d885d70ca0 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:27:56 +0300 Subject: [PATCH] =?UTF-8?q?Use=20string=20serializ=D1=84tion/deserializati?= =?UTF-8?q?on=20for=20DateTime=20structure=20(#147)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Requests/CreateLogItemRequest.cs | 1 - .../Requests/FinishLaunchRequest.cs | 5 +-- .../Requests/FinishTestItemRequest.cs | 1 - .../Requests/MergeLaunchesRequest.cs | 2 - .../Requests/StartLaunchRequest.cs | 1 - .../Requests/StartTestItemRequest.cs | 1 - .../Abstractions/Responses/LaunchResponse.cs | 2 - .../Abstractions/Responses/LogItemResponse.cs | 1 - .../Responses/TestItemResponse.cs | 3 -- .../Converters/DateTimeUnixEpochConverter.cs | 44 ------------------- 10 files changed, 1 insertion(+), 60 deletions(-) delete mode 100644 src/ReportPortal.Client/Converters/DateTimeUnixEpochConverter.cs diff --git a/src/ReportPortal.Client/Abstractions/Requests/CreateLogItemRequest.cs b/src/ReportPortal.Client/Abstractions/Requests/CreateLogItemRequest.cs index 36306e9f..a200b4fe 100644 --- a/src/ReportPortal.Client/Abstractions/Requests/CreateLogItemRequest.cs +++ b/src/ReportPortal.Client/Abstractions/Requests/CreateLogItemRequest.cs @@ -24,7 +24,6 @@ public class CreateLogItemRequest /// /// Date time of log item. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime Time { get; set; } = DateTime.UtcNow; /// diff --git a/src/ReportPortal.Client/Abstractions/Requests/FinishLaunchRequest.cs b/src/ReportPortal.Client/Abstractions/Requests/FinishLaunchRequest.cs index bdb158bb..a7bad2a0 100644 --- a/src/ReportPortal.Client/Abstractions/Requests/FinishLaunchRequest.cs +++ b/src/ReportPortal.Client/Abstractions/Requests/FinishLaunchRequest.cs @@ -1,6 +1,4 @@ -using ReportPortal.Client.Converters; -using System; -using System.Text.Json.Serialization; +using System; namespace ReportPortal.Client.Abstractions.Requests { @@ -12,7 +10,6 @@ public class FinishLaunchRequest /// /// Gets or sets the date and time when the launch execution is finished. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime EndTime { get; set; } = DateTime.UtcNow; } } diff --git a/src/ReportPortal.Client/Abstractions/Requests/FinishTestItemRequest.cs b/src/ReportPortal.Client/Abstractions/Requests/FinishTestItemRequest.cs index 19b53ee8..5412e533 100644 --- a/src/ReportPortal.Client/Abstractions/Requests/FinishTestItemRequest.cs +++ b/src/ReportPortal.Client/Abstractions/Requests/FinishTestItemRequest.cs @@ -20,7 +20,6 @@ public class FinishTestItemRequest /// /// Gets or sets the date and time when the test item is finished. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime EndTime { get; set; } = DateTime.UtcNow; /// diff --git a/src/ReportPortal.Client/Abstractions/Requests/MergeLaunchesRequest.cs b/src/ReportPortal.Client/Abstractions/Requests/MergeLaunchesRequest.cs index 774cf299..79627e20 100644 --- a/src/ReportPortal.Client/Abstractions/Requests/MergeLaunchesRequest.cs +++ b/src/ReportPortal.Client/Abstractions/Requests/MergeLaunchesRequest.cs @@ -30,13 +30,11 @@ public class MergeLaunchesRequest /// /// Gets or sets the date and time when the launch is executed. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime StartTime { get; set; } /// /// Gets or sets the date and time when the launch is finished. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime EndTime { get; set; } /// diff --git a/src/ReportPortal.Client/Abstractions/Requests/StartLaunchRequest.cs b/src/ReportPortal.Client/Abstractions/Requests/StartLaunchRequest.cs index fef20b54..0796f913 100644 --- a/src/ReportPortal.Client/Abstractions/Requests/StartLaunchRequest.cs +++ b/src/ReportPortal.Client/Abstractions/Requests/StartLaunchRequest.cs @@ -30,7 +30,6 @@ public class StartLaunchRequest /// /// Gets or sets the date and time when the launch is executed. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime StartTime { get; set; } = DateTime.UtcNow; /// diff --git a/src/ReportPortal.Client/Abstractions/Requests/StartTestItemRequest.cs b/src/ReportPortal.Client/Abstractions/Requests/StartTestItemRequest.cs index 084ae58a..fab85254 100644 --- a/src/ReportPortal.Client/Abstractions/Requests/StartTestItemRequest.cs +++ b/src/ReportPortal.Client/Abstractions/Requests/StartTestItemRequest.cs @@ -29,7 +29,6 @@ public class StartTestItemRequest /// /// Date time when new test item is created. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime StartTime { get; set; } = DateTime.UtcNow; /// diff --git a/src/ReportPortal.Client/Abstractions/Responses/LaunchResponse.cs b/src/ReportPortal.Client/Abstractions/Responses/LaunchResponse.cs index ee50d58c..5278a27c 100644 --- a/src/ReportPortal.Client/Abstractions/Responses/LaunchResponse.cs +++ b/src/ReportPortal.Client/Abstractions/Responses/LaunchResponse.cs @@ -45,13 +45,11 @@ public class LaunchResponse /// /// Gets or sets the start time of the launch. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime StartTime { get; set; } /// /// Gets or sets the end time of the launch. /// - [JsonConverter(typeof(NullableDateTimeUnixEpochConverter))] public DateTime? EndTime { get; set; } /// diff --git a/src/ReportPortal.Client/Abstractions/Responses/LogItemResponse.cs b/src/ReportPortal.Client/Abstractions/Responses/LogItemResponse.cs index e750a2ed..aa5eea67 100644 --- a/src/ReportPortal.Client/Abstractions/Responses/LogItemResponse.cs +++ b/src/ReportPortal.Client/Abstractions/Responses/LogItemResponse.cs @@ -34,7 +34,6 @@ public class LogItemResponse /// /// Gets or sets the time when the log item was created. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime Time { get; set; } /// diff --git a/src/ReportPortal.Client/Abstractions/Responses/TestItemResponse.cs b/src/ReportPortal.Client/Abstractions/Responses/TestItemResponse.cs index 9716d3f5..c62f621c 100644 --- a/src/ReportPortal.Client/Abstractions/Responses/TestItemResponse.cs +++ b/src/ReportPortal.Client/Abstractions/Responses/TestItemResponse.cs @@ -40,13 +40,11 @@ public class TestItemResponse /// /// Gets or sets the start time of the test item. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime StartTime { get; set; } /// /// Gets or sets the end time of the test item. /// - [JsonConverter(typeof(NullableDateTimeUnixEpochConverter))] public DateTime? EndTime { get; set; } /// @@ -191,7 +189,6 @@ public class ExternalSystemIssue /// /// Gets or sets the submit date of the external system issue. /// - [JsonConverter(typeof(DateTimeUnixEpochConverter))] public DateTime SubmitDate { get; set; } /// diff --git a/src/ReportPortal.Client/Converters/DateTimeUnixEpochConverter.cs b/src/ReportPortal.Client/Converters/DateTimeUnixEpochConverter.cs deleted file mode 100644 index 9dd8872a..00000000 --- a/src/ReportPortal.Client/Converters/DateTimeUnixEpochConverter.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace ReportPortal.Client.Converters -{ - sealed class DateTimeUnixEpochConverter : JsonConverter - { - private static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - - public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var unixTime = reader.GetInt64(); - - return UNIX_EPOCH.AddMilliseconds(unixTime); - } - - public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) - { - var unixTime = Convert.ToInt64((value - UNIX_EPOCH).TotalMilliseconds); - - writer.WriteNumberValue(unixTime); - } - } - - sealed class NullableDateTimeUnixEpochConverter : JsonConverter - { - private static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - - public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var unixTime = reader.GetInt64(); - - return UNIX_EPOCH.AddMilliseconds(unixTime); - } - - public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options) - { - var unixTime = Convert.ToInt64((value - UNIX_EPOCH).Value.TotalMilliseconds); - - writer.WriteNumberValue(unixTime); - } - } -}