Function decodeTime

  • 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.

    Parameters

    • ulid: string

      The ULID to extract the timestamp from.

    Returns number

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

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

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

    assertEquals(decodeTime(ulidString), timestamp);