decodeTime

import { decodeTime } from "jsr:@ende/ulid";

function

function decodeTime(ulid: string): number

Extracts the number of milliseconds since the Unix epoch that had passed when the ULID was generated. If the ULID is malformed, an error will be thrown.

ulid: string

The ULID to extract the timestamp from.

Returns

The number of milliseconds since the Unix epoch that had passed when the ULID was generated.

Example: Decode the time from a ULID

import { decodeTime, ulid } from "@ende/ulid";
import { assertEquals } from "@ende/assert";

const timestamp = 150_000;
const ulidString = ulid(timestamp);

assertEquals(decodeTime(ulidString), timestamp);

Source