From e923d65d535307ad733ced4c45dc82eca4259093 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Sat, 15 Nov 2025 18:21:15 +0100 Subject: [PATCH] Clamp TL stamps to 0..int.MaxValue, mapping edge to DateTime.Min/MaxValueaa --- src/TL.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/TL.cs b/src/TL.cs index 135d972..0bb4583 100644 --- a/src/TL.cs +++ b/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) {