Truncate SystemClock to Seconds Precision (#1110)

This commit is contained in:
Ben Adams 2017-02-06 22:36:42 +00:00 committed by Chris R
parent 7dd6ee791a
commit fea5d5cfdc
1 changed files with 3 additions and 3 deletions

View File

@ -7,7 +7,7 @@ using System;
namespace Microsoft.AspNetCore.Authentication
{
/// <summary>
/// Provides access to the normal system clock.
/// Provides access to the normal system clock with precision in seconds.
/// </summary>
public class SystemClock : ISystemClock
{
@ -20,8 +20,8 @@ namespace Microsoft.AspNetCore.Authentication
{
// the clock measures whole seconds only, to have integral expires_in results, and
// because milliseconds do not round-trip serialization formats
DateTimeOffset utcNow = DateTimeOffset.UtcNow;
return utcNow.AddMilliseconds(-utcNow.Millisecond);
var utcNowPrecisionSeconds = new DateTime((DateTime.UtcNow.Ticks / TimeSpan.TicksPerSecond) * TimeSpan.TicksPerSecond, DateTimeKind.Utc);
return new DateTimeOffset(utcNowPrecisionSeconds);
}
}
}