Skip to content

AsOf

Timestamp with live relative formatting and a stated timezone.
Implemented
Status
Implemented
Family
1 of 13
Registry
@lopifi/as-of
npx shadcn@latest add @lopifi/theme @lopifi/as-of

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

The four-layer spec

<AsOf date={lastSync} />   // "2m ago"  ·  title="6 Sep 2026, 09:12 UTC"

Relative under an hour, absolute beyond. Timezone always stated in the absolute form. Updates from a single shared interval — never one setInterval per instance — and pauses on tab hide and off-screen.

Every figure in this system is accompanied by one of these. A balance without an "as of" is a rumor.

Lifted verbatim from Primitives. The doc and this page are the same paragraphs, so they cannot disagree.

What lands in your repository

One component is never one file. Everything below is copied into your project, where you own it.

Files

components/ledger/as-of.tsx

Lopifi dependencies · 4
cnfiscal-periodtooltipuse-shared-now
npm packages
@base-ui-components/reactclsxtailwind-merge
Registry entry
/r/as-of.json

The whole component

No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.

components/ledger/as-of.tsx
"use client";

import * as React from "react";
import { useSharedNow } from "@/hooks/ledger/use-shared-now";
import { cn } from "@/lib/ledger/cn";
import { formatDate, formatRelative, formatTimestamp } from "@/lib/ledger/fiscal-period";
import { Tooltip } from "@/components/ledger/tooltip";

export interface AsOfProps extends React.ComponentPropsWithoutRef<"time"> {
  /**
   * Beyond an hour, render the date alone and leave the clock time and zone to
   * the tooltip. For dense meta rows, where the full stamp is the single
   * longest run of text on a card and the least often read.
   *
   * Off by default: the unabridged form states its timezone inline, and that
   * is the correct default for a figure whose basis is being asserted.
   */
  compact?: boolean;
  date: Date;
  /** Suppress the absolute-timestamp tooltip — e.g. inside a cell that has its own. */
  noTooltip?: boolean;
  prefix?: string;
  timeZone?: string;
}

/**
 * A balance without an "as of" is a rumour.
 *
 * Relative under an hour, absolute beyond, timezone always stated. Driven by
 * one shared interval that pauses on tab hide — never one per instance.
 */
export const AsOf = React.forwardRef<HTMLTimeElement, AsOfProps>(
  ({ className, date, timeZone = "UTC", prefix, noTooltip, compact, ...props }, ref) => {
    const now = useSharedNow();
    const absolute = formatTimestamp(date, timeZone);
    const initial = compact ? formatDate(date) : absolute;
    const [text, setText] = React.useState(initial);

    // Render the absolute form on the server and on first paint so hydration
    // matches; swap to relative once the client clock is available.
    React.useEffect(() => {
      const relative = formatRelative(date, now);
      // `formatRelative` falls back to the full stamp beyond an hour; in
      // compact mode that fallback is the date alone.
      setText(compact && relative === formatTimestamp(date) ? formatDate(date) : relative);
    }, [compact, date, now]);

    // Supplementary by definition — the relative form is already readable, and
    // the absolute one is a restatement. Exactly what a hover tooltip is for.
    return (
      <Tooltip content={absolute} disabled={noTooltip}>
        <time
          // A stamp never breaks: "30 Sep / 2026" across two lines reads as two
          // facts. A tight row moves the whole stamp, not half of it.
          className={cn("numeric whitespace-nowrap text-caption text-text-tertiary", className)}
          dateTime={date.toISOString()}
          ref={ref}
          {...props}
        >
          {/* Words in the text face, the stamp in the figure face. */}
          {prefix ? <span className="font-sans">{`${prefix} `}</span> : null}
          {text}
        </time>
      </Tooltip>
    );
  },
);
AsOf.displayName = "AsOf";

The accounting it encodes

Concepts this component renders. Each one is defined once, in the lexicon, and used identically in the code and the copy.

Also in Primitives

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

Elsewhere in the system

Where AsOf sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.

Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.

Told when Primitives changes

Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.