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