From 7291b8d3e4712c393a8493982895d4a7ce3ca233 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 13 Nov 2015 15:34:34 -0500 Subject: [PATCH] use DateTime.TryParse --- .../Security/PluginSecurityManager.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs index 1176407ce3..d4fa74a86c 100644 --- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -178,11 +178,35 @@ namespace MediaBrowser.Common.Implementations.Security Email = response.email, PlanType = response.planType, SupporterKey = response.supporterKey, - ExpirationDate = string.IsNullOrWhiteSpace(response.expDate) ? (DateTime?)null : DateTime.Parse(response.expDate), - RegistrationDate = DateTime.Parse(response.regDate), IsActiveSupporter = IsMBSupporter }; + if (!string.IsNullOrWhiteSpace(response.expDate)) + { + DateTime parsedDate; + if (DateTime.TryParse(response.expDate, out parsedDate)) + { + info.ExpirationDate = parsedDate; + } + else + { + _logger.Error("Failed to parse expDate: {0}", response.expDate); + } + } + + if (!string.IsNullOrWhiteSpace(response.regDate)) + { + DateTime parsedDate; + if (DateTime.TryParse(response.regDate, out parsedDate)) + { + info.RegistrationDate = parsedDate; + } + else + { + _logger.Error("Failed to parse regDate: {0}", response.regDate); + } + } + info.IsExpiredSupporter = info.ExpirationDate.HasValue && info.ExpirationDate < DateTime.UtcNow && !string.IsNullOrWhiteSpace(info.SupporterKey); return info;