Last active
September 13, 2022 19:06
-
-
Save IvanAdmaers/3caefd027872badc49c7710b375d1024 to your computer and use it in GitHub Desktop.
generateUTCId
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
/** | |
* This function returns an ID that depends on UTC | |
* !WARNING! It might return non-unique ID when the function | |
* will call more than one time in one milliseconds | |
* generateUTCId() === generateUTCId() // true | |
*/ | |
export const generateUTCId = (): number => { | |
const date = new Date(); | |
const components = [ | |
date.getUTCFullYear(), | |
date.getUTCMonth(), | |
date.getUTCDate(), | |
date.getUTCHours(), | |
date.getUTCMinutes(), | |
date.getUTCSeconds(), | |
date.getUTCMilliseconds(), | |
]; | |
const id = +components.join(''); | |
return id; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment