Skip to content

Commit

Permalink
added error catching around datetimeoffset conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomáš Pozler committed Oct 17, 2023
1 parent 2d03578 commit b891939
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,15 +649,19 @@ public static Currency[] ToCurrencyArray(GrpcCurrencyArray arrayValue)

public static DateTimeOffset ToDateTimeOffset(GrpcOffsetDateTime offsetDateTimeValue)
{
if (string.IsNullOrEmpty(offsetDateTimeValue.Offset))
try
{
TimeSpan hourOffset = TimeSpan.FromHours(int.Parse(offsetDateTimeValue.Offset.Substring(1, 2)));
bool add = offsetDateTimeValue.Offset.ElementAt(0) == '+';
TimeSpan offset = add ? hourOffset : hourOffset.Negate();
return DateTimeOffset.FromUnixTimeSeconds(offsetDateTimeValue.Timestamp.Seconds)
.ToOffset(offset);
}
catch (Exception)
{
Console.WriteLine(offsetDateTimeValue.Timestamp + " " +offsetDateTimeValue.Offset);
return DateTimeOffset.Now;
}
TimeSpan hourOffset = TimeSpan.FromHours(int.Parse(offsetDateTimeValue.Offset.Substring(1, 2)));
bool add = offsetDateTimeValue.Offset.ElementAt(0) == '+';
TimeSpan offset = add ? hourOffset : hourOffset.Negate();
return DateTimeOffset.FromUnixTimeSeconds(offsetDateTimeValue.Timestamp.Seconds)
.ToOffset(offset);
}

public static DateTimeOffset[] ToDateTimeOffsetArray(GrpcOffsetDateTimeArray arrayValue)
Expand Down

0 comments on commit b891939

Please sign in to comment.