diff --git a/ess/src/API/EMBC.ESS.Utilities.Cas/Contract.cs b/ess/src/API/EMBC.ESS.Utilities.Cas/Contract.cs index 2c62610e7..1aa9ff0f6 100644 --- a/ess/src/API/EMBC.ESS.Utilities.Cas/Contract.cs +++ b/ess/src/API/EMBC.ESS.Utilities.Cas/Contract.cs @@ -212,7 +212,7 @@ public class CasDateJsonConverter : JsonConverter public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var tmp = DateTime.SpecifyKind(DateTime.Parse(reader.GetString() ?? string.Empty), DateTimeKind.Unspecified); - return TimeZoneInfo.ConvertTimeToUtc(TimeZoneInfo.ConvertTimeBySystemTimeZoneId(tmp, DateTimeEx.GetPSTTimeZone())); + return tmp.FromUnspecifiedPstToUtc(); } public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) diff --git a/ess/src/API/EMBC.Tests.Integration.ESS/Resources/PaymentsTests.cs b/ess/src/API/EMBC.Tests.Integration.ESS/Resources/PaymentsTests.cs index 90a745b46..da35cede5 100644 --- a/ess/src/API/EMBC.Tests.Integration.ESS/Resources/PaymentsTests.cs +++ b/ess/src/API/EMBC.Tests.Integration.ESS/Resources/PaymentsTests.cs @@ -271,11 +271,10 @@ await repository.Manage(new IssuePaymentsBatchRequest public async Task ConvertPstToUtc() { var registrantId = await CreateNewRegistrant(); - var tmp = DateTime.SpecifyKind(DateTime.Parse("07-SEP-2023 14:00:41"), DateTimeKind.Unspecified); - tmp = TimeZoneInfo.ConvertTimeToUtc(TimeZoneInfo.ConvertTimeBySystemTimeZoneId(tmp, DateTimeEx.GetPSTTimeZone())); + var tmp = DateTime.SpecifyKind(DateTime.Parse("07-SEP-2023 14:23:41"), DateTimeKind.Unspecified); + tmp = tmp.FromUnspecifiedPstToUtc(); tmp.Second.ShouldBe(41); - tmp.Minute.ShouldBe(0); - tmp.Hour.ShouldBe(21); + tmp.Minute.ShouldBe(23); } } } diff --git a/shared/src/EMBC.Utilities/Extensions/DateTimeEx.cs b/shared/src/EMBC.Utilities/Extensions/DateTimeEx.cs index 531ccd05c..51b53dd8e 100644 --- a/shared/src/EMBC.Utilities/Extensions/DateTimeEx.cs +++ b/shared/src/EMBC.Utilities/Extensions/DateTimeEx.cs @@ -12,7 +12,14 @@ public static DateTime ToPST(this DateTime date) return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(date, GetPSTTimeZone()); } - public static string GetPSTTimeZone() + public static DateTime FromUnspecifiedPstToUtc(this DateTime date) + { + //convert from Unspecified PST to UTC + if (date.Kind != DateTimeKind.Unspecified) date = DateTime.SpecifyKind(date, DateTimeKind.Unspecified); + return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(date, GetPSTTimeZone(), GetUTCTimeZone()); + } + + private static string GetPSTTimeZone() { return Environment.OSVersion.Platform switch {