From b8919399e6a5119f90dc879143dfe3a2c9a329ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pozler?= Date: Tue, 17 Oct 2023 20:29:15 +0200 Subject: [PATCH] added error catching around datetimeoffset conversion --- .../DataTypes/EvitaDataTypesConverter.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs b/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs index ab1e172..143825b 100644 --- a/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs +++ b/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs @@ -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)