-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(web-analytics): Add timestamp utils and uuidv7 code to plugin-server #27070
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, left a non-blocking comment
if (!year || !month || !day) { | ||
throw new Error('Failed to get year, month, or day') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this can ever happen, formatToParts
will always return a value. If you attempt to pass anything that couldn't be formatted it will raise RangeError
Are you doing this for TS purposes? If so, because formatToParts
never fails to return a value we might do this to collect the values instead - it's deterministic AFAICT
const [month, , day, , year] = parts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is just to make typescript happy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it was - I looked through the docs and I do think the order is guaranteed https://tc39.es/ecma402/#sec-formatdatetimetoparts but I'm not confident enough to assume this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like code 👍
// we set fully random values for rand_a and rand_b | ||
|
||
const array = new Uint8Array(16) | ||
// 48 bits for time, WILL FAIL in 10 895 CE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS integers are also 48 bits (out of a 64 bit number), so there will be bigger problems
if (!year || !month || !day) { | ||
throw new Error('Failed to get year, month, or day') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is just to make typescript happy?
Problem
Pulled out of #25915 to make it easier to review
Changes
Added a UUIDv7 class, and some extra timestamp utils which will be used in cookieless mode
Does this work well for both Cloud and self-hosted?
Yes
How did you test this code?
Added some tests