A rhythm game net ranking service built on ATproto.
1using System;
2using Godot;
3
4public class TimestampId {
5 //Base32 encode with encoding variant sort - ported from Bluesky official code
6 private const string S32_CHAR = "234567abcdefghijklmnopqrstuvwxyz";
7
8 public static string S32Encode(long value) {
9 string s = "";
10 while (value > 0) {
11 int c = (int) (value % 32);
12 value >>= 5;
13 s = S32_CHAR[c] + s;
14 }
15 return s;
16 }
17
18 public static long S32Decode(string value) {
19 long i = 0;
20 foreach (char c in value) {
21 i = i * 32 + S32_CHAR.IndexOf(c);
22 }
23 return i;
24 }
25
26 public static string EncodeTid(DateTime timestamp) {
27 //Bsky uses a clock ID since JS time doesn't have microseconds,
28 //so we'll kind of match that!
29 long baseTime = ((DateTimeOffset)timestamp).ToUnixTimeMilliseconds();
30 string millis = S32Encode(baseTime*1000);
31 string micros = S32Encode(timestamp.Microsecond).PadLeft(2, '2');
32 return $"{millis}{micros}";
33 }
34}