Update id generation methods

This commit is contained in:
syuilo 2019-04-14 01:08:26 +09:00
parent b247be80cc
commit e64912545a
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
6 changed files with 30 additions and 72 deletions

View file

@ -1,26 +0,0 @@
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();
}