summaryrefslogtreecommitdiff
path: root/src/misc/aidc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/aidc.ts')
-rw-r--r--src/misc/aidc.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/misc/aidc.ts b/src/misc/aidc.ts
new file mode 100644
index 0000000000..75168ac307
--- /dev/null
+++ b/src/misc/aidc.ts
@@ -0,0 +1,26 @@
+// AID(Cheep)
+// 長さ6の[2000年1月1日からの経過秒をbase36でエンコードしたもの] + 長さ3の[ランダムな文字列]
+
+const CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
+const TIME2000 = 946684800000;
+
+function getTime(time: number) {
+ time = time - TIME2000;
+ if (time < 0) time = 0;
+ time = Math.floor(time / 1000);
+ return time.toString(36);
+}
+
+function getRandom() {
+ let str = '';
+
+ for (let i = 0; i < 3; i++) {
+ str += CHARS[Math.floor(Math.random() * CHARS.length)];
+ }
+
+ return str;
+}
+
+export function genAidc(date: Date): string {
+ return getTime(date.getTime()).padStart(6, CHARS[0]) + getRandom();
+}