mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-25 14:16:43 -06:00
27 lines
447 B
TypeScript
27 lines
447 B
TypeScript
|
const CHARS = '0123456789abcdef';
|
||
|
|
||
|
function getTime(time: number) {
|
||
|
if (time < 0) time = 0;
|
||
|
if (time === 0) {
|
||
|
return CHARS[0];
|
||
|
}
|
||
|
|
||
|
time = Math.floor(time / 1000);
|
||
|
|
||
|
return time.toString(16);
|
||
|
}
|
||
|
|
||
|
function getRandom() {
|
||
|
let str = '';
|
||
|
|
||
|
for (let i = 0; i < 16; i++) {
|
||
|
str += CHARS[Math.floor(Math.random() * CHARS.length)];
|
||
|
}
|
||
|
|
||
|
return str;
|
||
|
}
|
||
|
|
||
|
export function genObjectId(date: Date): string {
|
||
|
return getTime(date.getTime()) + getRandom();
|
||
|
}
|