fix: Use double precision for X-Reset-After, set CultureInfo when parsing numeric types (#1375)

* Parse double for X-Reset-After instead of float, needs more precision

Float did not contain enough precision to store the millisecond unix
time value, which resulted in the second and millisecond values being
slightly off.

This can be easily tested using:

```cs
> DateTimeOffset.FromUnixTimeMilliseconds((long)(1470173022.123f *
1000)).Millisecond
160 // wrong

> DateTimeOffset.FromUnixTimeMilliseconds((long)(1470173022.123 *
1000)).Millisecond
123 // correct
```

* Parse RateLimit-Reset using an IFormatProvider

* State NumberStyle and use CultureInfo.InvariantCulture for any parsing

This updates most occurances in the code where a Parse or TryParse method was used to explicitly state the NumberStyle, and to use CultureInfo.InvariantCulture.
CultureInfo was used over NumberInfo, as it also works on DateTime parsing too.

* Use default format spec in Commands
This commit is contained in:
Chris Johnston
2019-09-14 09:38:26 -07:00
committed by Christopher F
parent 3755a027b3
commit 606dac3e1a
7 changed files with 19 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Discord.Rest;
@@ -60,10 +61,10 @@ namespace Discord.WebSocket
}
if (model.Discriminator.IsSpecified)
{
var newVal = ushort.Parse(model.Discriminator.Value);
var newVal = ushort.Parse(model.Discriminator.Value, NumberStyles.None, CultureInfo.InvariantCulture);
if (newVal != DiscriminatorValue)
{
DiscriminatorValue = ushort.Parse(model.Discriminator.Value);
DiscriminatorValue = ushort.Parse(model.Discriminator.Value, NumberStyles.None, CultureInfo.InvariantCulture);
hasChanges = true;
}
}