Skip to content

Commit

Permalink
Extracting .NET cookie expiration time calculation to private method
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jul 8, 2019
1 parent ad9f331 commit a417af2
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions dotnet/src/webdriver/Cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,7 @@ public static Cookie FromDictionary(Dictionary<string, object> rawCookie)
DateTime? expires = null;
if (rawCookie.ContainsKey("expiry") && rawCookie["expiry"] != null)
{
double seconds = 0;
if (double.TryParse(rawCookie["expiry"].ToString(), NumberStyles.Number, CultureInfo.InvariantCulture, out seconds))
{
try
{
expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(seconds).ToLocalTime();
}
catch (ArgumentOutOfRangeException)
{
expires = DateTime.MaxValue.ToLocalTime();
}
}
expires = ConvertExpirationTime(rawCookie["expiry"].ToString());
}

bool secure = false;
Expand Down Expand Up @@ -329,5 +318,24 @@ private static string StripPort(string domain)
{
return string.IsNullOrEmpty(domain) ? null : domain.Split(':')[0];
}

private static DateTime? ConvertExpirationTime(string expirationTime)
{
DateTime? expires = null;
double seconds = 0;
if (double.TryParse(expirationTime, NumberStyles.Number, CultureInfo.InvariantCulture, out seconds))
{
try
{
expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(seconds).ToLocalTime();
}
catch (ArgumentOutOfRangeException)
{
expires = DateTime.MaxValue.ToLocalTime();
}
}

return expires;
}
}
}

0 comments on commit a417af2

Please sign in to comment.