2019-04-13 18:08:26 +02:00
|
|
|
// AID
|
|
|
|
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さ2の[ノイズ文字列]
|
|
|
|
|
|
|
|
import * as cluster from 'cluster';
|
|
|
|
|
|
|
|
const TIME2000 = 946684800000;
|
|
|
|
let counter = process.pid + (cluster.isMaster ? 0 : cluster.worker.id);
|
|
|
|
|
|
|
|
function getTime(time: number) {
|
|
|
|
time = time - TIME2000;
|
|
|
|
if (time < 0) time = 0;
|
|
|
|
|
|
|
|
return time.toString(36).padStart(8, '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRandom() {
|
2019-04-13 19:21:57 +02:00
|
|
|
return counter.toString(36).padStart(2, '0').substr(2);
|
2019-04-13 18:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function genAid(date: Date): string {
|
|
|
|
counter++;
|
|
|
|
return getTime(date.getTime()) + getRandom();
|
|
|
|
}
|