Use TimeSpan to represent time.

This commit is contained in:
Huo Yaoyuan 2017-09-24 03:23:31 +08:00
parent d277952e0f
commit c5aebf6401

View File

@ -70,13 +70,11 @@ namespace osu.Game.Online.API
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}"; protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
private double remainingTime => Math.Max(0, Timeout - (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - (startTime ?? 0))); private double remainingTime => Math.Max(0, Timeout - (DateTimeOffset.UtcNow - (startTime ?? DateTimeOffset.MinValue)).TotalMilliseconds);
public bool ExceededTimeout => remainingTime == 0; public bool ExceededTimeout => remainingTime == 0;
private double? startTime; private DateTimeOffset? startTime;
public double StartTime => startTime ?? -1;
protected APIAccess API; protected APIAccess API;
protected WebRequest WebRequest; protected WebRequest WebRequest;
@ -96,7 +94,7 @@ namespace osu.Game.Online.API
return; return;
if (startTime == null) if (startTime == null)
startTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); startTime = DateTimeOffset.UtcNow;
if (remainingTime <= 0) if (remainingTime <= 0)
throw new TimeoutException(@"API request timeout hit"); throw new TimeoutException(@"API request timeout hit");