forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

uuid-time.ts13 lines, 559 bytesHistoryRawDownload
1/**
2 * The creation instant embedded in a UUIDv7 id (its first 48 bits are unix
3 * milliseconds), or `null` for any other id.
4 *
5 * Only for ordering records the backend gives no date for — an exam that was
6 * never scheduled still sorts by when it was created. Never shown as a date:
7 * it says when the row was made, not when anything happened.
8 */
9export function uuidV7Ms(id: string): number | null {
10 const match = /^([0-9a-f]{8})-([0-9a-f]{4})-7[0-9a-f]{3}-/i.exec(id);
11 if (!match) return null;
12 return Number.parseInt(match[1] + match[2], 16);
13}