mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Clamp TL stamps to 0..int.MaxValue, mapping edge to DateTime.Min/MaxValueaa
This commit is contained in:
parent
4ad2f0a212
commit
e923d65d53
11
src/TL.cs
11
src/TL.cs
|
|
@ -325,13 +325,14 @@ namespace TL
|
|||
}
|
||||
|
||||
internal static void WriteTLStamp(this BinaryWriter writer, DateTime datetime)
|
||||
=> writer.Write(datetime == DateTime.MaxValue ? int.MaxValue : (int)(datetime.ToUniversalTime().Ticks / 10000000 - 62135596800L));
|
||||
=> writer.Write((int)Math.Min(Math.Max(datetime.ToUniversalTime().Ticks / 10000000 - 62135596800L, 0), int.MaxValue));
|
||||
|
||||
internal static DateTime ReadTLStamp(this BinaryReader reader)
|
||||
internal static DateTime ReadTLStamp(this BinaryReader reader) => reader.ReadInt32() switch
|
||||
{
|
||||
int unixstamp = reader.ReadInt32();
|
||||
return unixstamp == int.MaxValue ? DateTime.MaxValue : new((unixstamp + 62135596800L) * 10000000, DateTimeKind.Utc);
|
||||
}
|
||||
<= 0 => default,
|
||||
int.MaxValue => DateTime.MaxValue,
|
||||
int unixstamp => new((unixstamp + 62135596800L) * 10000000, DateTimeKind.Utc)
|
||||
};
|
||||
|
||||
internal static void WriteTLString(this BinaryWriter writer, string str)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue