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:
committed by
Christopher F
parent
3755a027b3
commit
606dac3e1a
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Discord
|
||||
@@ -76,7 +77,7 @@ namespace Discord
|
||||
var bytes = Convert.FromBase64String(encoded);
|
||||
var idStr = Encoding.UTF8.GetString(bytes);
|
||||
// try to parse a ulong from the resulting string
|
||||
if (ulong.TryParse(idStr, out var id))
|
||||
if (ulong.TryParse(idStr, NumberStyles.None, CultureInfo.InvariantCulture, out var id))
|
||||
return id;
|
||||
}
|
||||
catch (DecoderFallbackException)
|
||||
|
||||
Reference in New Issue
Block a user