using System; using Godot; public class TimestampId { //Base32 encode with encoding variant sort - ported from Bluesky official code private const string S32_CHAR = "234567abcdefghijklmnopqrstuvwxyz"; public static string S32Encode(long value) { string s = ""; while (value > 0) { int c = (int) (value % 32); value >>= 5; s = S32_CHAR[c] + s; } return s; } public static long S32Decode(string value) { long i = 0; foreach (char c in value) { i = i * 32 + S32_CHAR.IndexOf(c); } return i; } public static string EncodeTid(DateTime timestamp) { //Bsky uses a clock ID since JS time doesn't have microseconds, //so we'll kind of match that! long baseTime = ((DateTimeOffset)timestamp).ToUnixTimeMilliseconds(); string millis = S32Encode(baseTime*1000); string micros = S32Encode(timestamp.Microsecond).PadLeft(2, '2'); return $"{millis}{micros}"; } }