Skip to content

Commit

Permalink
EMBCESSMOD-4687: Updated Date Convert logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKayfish committed Sep 9, 2023
1 parent 507bb0d commit c3d7f92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ess/src/API/EMBC.ESS.Utilities.Cas/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public class CasDateJsonConverter : JsonConverter<DateTime>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
9 changes: 8 additions & 1 deletion shared/src/EMBC.Utilities/Extensions/DateTimeEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit c3d7f92

Please sign in to comment.