Skip to content

Instantly share code, notes, and snippets.

@IvanAdmaers
Last active September 13, 2022 19:06
Show Gist options
  • Save IvanAdmaers/3caefd027872badc49c7710b375d1024 to your computer and use it in GitHub Desktop.
Save IvanAdmaers/3caefd027872badc49c7710b375d1024 to your computer and use it in GitHub Desktop.
generateUTCId
/**
* 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