2019-04-14 01:08:26 +09: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-14 02:33:50 +09:00
|
|
|
return counter.toString(36).padStart(2, '0').slice(-2);
|
2019-04-14 01:08:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export function genAid(date: Date): string {
|
|
|
|
counter++;
|
|
|
|
return getTime(date.getTime()) + getRandom();
|
|
|
|
}
|