Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public sealed class Cookie
private bool m_secure; // Do not rename (binary serialization)
[System.Runtime.Serialization.OptionalField]
private bool m_httpOnly = false; // Do not rename (binary serialization)
private DateTime m_timeStamp = DateTime.Now; // Do not rename (binary serialization)
private DateTime m_timeStamp = DateTime.UtcNow; // Do not rename (binary serialization)
private string m_value = string.Empty; // Do not rename (binary serialization)
private int m_version; // Do not rename (binary serialization)

Expand Down Expand Up @@ -199,13 +199,13 @@ public bool Expired
{
get
{
return (m_expires != DateTime.MinValue) && (m_expires.ToLocalTime() <= DateTime.Now);
return (m_expires != DateTime.MinValue) && (m_expires.ToUniversalTime() <= DateTime.UtcNow);
}
set
{
if (value)
{
m_expires = DateTime.Now;
m_expires = DateTime.UtcNow;
}
}
}
Expand Down Expand Up @@ -801,7 +801,7 @@ internal void ToString(StringBuilder sb)
}
if (Expires != DateTime.MinValue)
{
int seconds = (int)(Expires.ToLocalTime() - DateTime.Now).TotalSeconds;
int seconds = (int)(Expires.ToUniversalTime() - DateTime.UtcNow).TotalSeconds;
if (seconds < 0)
{
// This means that the cookie has already expired. Set Max-Age to 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public static void Expired_GetSet_Success()
Cookie c = new Cookie();
Assert.False(c.Expired);

c.Expires = DateTime.Now.AddDays(-1);
c.Expires = DateTime.UtcNow.AddDays(-1);
Assert.True(c.Expired);

c.Expires = DateTime.Now.AddDays(1);
c.Expires = DateTime.UtcNow.AddDays(1);
Assert.False(c.Expired);

c.Expired = true;
Expand All @@ -135,7 +135,7 @@ public static void Expires_GetSet_Success()
Cookie c = new Cookie();
Assert.Equal(c.Expires, DateTime.MinValue);

DateTime dt = DateTime.Now;
DateTime dt = DateTime.UtcNow;
c.Expires = dt;
Assert.Equal(dt, c.Expires);
}
Expand Down Expand Up @@ -226,7 +226,8 @@ public static void Secure_GetSet_Success()
[Fact]
public static void Timestamp_GetSet_Success()
{
DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0); //DateTime.Now changes as the test runs
//DateTime.UtcNow changes as the test runs
DateTime dt = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, 0);
Cookie c = new Cookie();
Assert.True(c.TimeStamp >= dt);
}
Expand Down