Created
April 13, 2019 16:44
-
-
Save mei23/48e39952458726c1b7e71dd615c41cbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CHARS = '0123456789abcdef'; | |
function getTime(time: number) { | |
if (time < 0) time = 0; | |
if (time === 0) { | |
return CHARS[0]; | |
} | |
time += 0x800000000000; | |
return time.toString(16).padStart(12, CHARS[0]); | |
} | |
function getRandom() { | |
let str = ''; | |
for (let i = 0; i < 12; i++) { | |
str += CHARS[Math.floor(Math.random() * CHARS.length)]; | |
} | |
return str; | |
} | |
export function genObjectId(date: Date): string { | |
return getTime(date.getTime()) + getRandom(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment