From b1a82e3e8e5a5dc8ce640b54fefc791dc2fdfa6c Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Fri, 28 Aug 2020 16:33:42 -0700 Subject: [PATCH] Fix parsing issue for empty ZDA messages --- src/NmeaParser/Nmea/Zda.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/NmeaParser/Nmea/Zda.cs b/src/NmeaParser/Nmea/Zda.cs index 91c306e..c62f32c 100644 --- a/src/NmeaParser/Nmea/Zda.cs +++ b/src/NmeaParser/Nmea/Zda.cs @@ -37,13 +37,13 @@ namespace NmeaParser.Messages } var time = StringToTimeSpan(message[0]); - var day = int.Parse(message[1], CultureInfo.InvariantCulture); - var month = int.Parse(message[2], CultureInfo.InvariantCulture); - var year = int.Parse(message[3], CultureInfo.InvariantCulture); - - FixDateTime = new DateTimeOffset(year, month, day, time.Hours, time.Minutes, - time.Seconds, TimeSpan.Zero); - + if (int.TryParse(message[1], NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out int day) && + int.TryParse(message[2], NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out int month) && + int.TryParse(message[3], NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out int year)) + { + FixDateTime = new DateTimeOffset(year, month, day, time.Hours, time.Minutes, + time.Seconds, TimeSpan.Zero); + } // Index 4 and 5 is used to specify a local time zone. // However I haven't come across any receiver that actually // specify this, so we're just ignoring it.