# Date Divider

> The line that splits a feed by day, such as Today or Yesterday, and a helper that groups items by day.

Page: https://uicontext.com/docs/components/date-divider

Group: Primitives.

## When to use

The line that splits a feed by day, such as Today or Yesterday, and a helper that groups items by day. Use [Group Header](https://uicontext.com/docs/components/group-header.md) instead when rows are grouped by something other than the day.

## Usage

```ts
import { DateDivider, groupByDay } from "./ui/uicontext/components/DateDivider.ts"

export const Feed = <M>(h: Html.H<M>, messages: ReadonlyArray<{ readonly id: string; readonly sentAt: string; readonly text: string }>, now: string) =>
	groupByDay(messages, (m) => m.sentAt, { now }).map(({ label, items }) => [DateDivider(h, { label }), ...items.map((m) => h.p.key(m.id).children(m.text))])
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A channel's days

The example the page opens with: Date Divider in “A channel's days”.

```ts title="src/demo.ts" source="www/src/examples/date-divider/demo.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { DateDivider, groupByDay } from "./ui/uicontext/components/DateDivider.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	feed: { inlineSize: "min(100%, 30rem)", blockSize: 380, overflowY: "auto", overscrollBehavior: "contain", paddingInline: space.md, borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel },
	day: { margin: 0, padding: 0, listStyle: "none" },
	message: { display: "grid", gap: 2, paddingBlock: space.sm },
	top: { display: "flex", gap: space.sm, alignItems: "baseline", fontSize: font.sm },
	name: { fontWeight: 600 },
	time: { fontSize: font.xs, color: color.muted, fontVariantNumeric: "tabular-nums" },
	text: { margin: 0, fontSize: font.sm, lineHeight: 1.5 },
})

// the instant the demo pretends it is, so the labels don't change from day to day
const now = "2026-12-04T16:30:00Z"
const timeZone = "Europe/London"
const clock = new Intl.DateTimeFormat("en-GB", { timeZone, hour: "2-digit", minute: "2-digit" })

const messages = [
	{ id: "1", from: "Lena Fischer", at: "2025-12-29T10:02:00Z", text: "Happy new year in advance, everyone." },
	{ id: "2", from: "Wei Chen", at: "2026-11-20T09:15:00Z", text: "Q4 targets are in the planning doc." },
	{ id: "3", from: "Priya Raman", at: "2026-12-01T14:40:00Z", text: "Northwind signed the renewal." },
	{ id: "4", from: "Tomás García", at: "2026-12-01T15:05:00Z", text: "Nice. I'll send the onboarding plan." },
	{ id: "5", from: "Ada Okafor", at: "2026-12-03T08:50:00Z", text: "Exports are failing for a few customers; looking now." },
	{ id: "6", from: "Ada Okafor", at: "2026-12-04T09:12:00Z", text: "Fixed: a timeout on the ledger API. Exports are back." },
	{ id: "7", from: "Priya Raman", at: "2026-12-04T09:20:00Z", text: "Thank you! Telling the customers now." },
]

// a team channel: a sticky day stays on top while its messages scroll under it
export const Channel = <M>(h: Html.H<M>) =>
	h.div.attrs({ tabindex: "0", "aria-label": "#support messages", ...sx(styles.feed) }).children(
		groupByDay(messages, (m) => m.at, { now, timeZone, locale: "en-GB" }).map((day) =>
			h.section.key(day.key).children(
				DateDivider(h, { label: day.label, sticky: true }),
				h.ul.attrs(sx(styles.day)).children(
					day.items.map((m) =>
						h.li.key(m.id).attrs(sx(styles.message)).children(
							h.div.attrs(sx(styles.top)).children(h.span.attrs(sx(styles.name)).children(m.from), h.span.attrs(sx(styles.time)).children(clock.format(new Date(m.at)))),
							h.p.attrs({ dir: "auto", ...sx(styles.text) }).children(m.text),
						)),
				),
			)),
	)
```

### Activity, in the reader's time zone

`align: "start"` puts the day at the line's start. `timeZone` decides which day an instant falls on.

```ts title="src/activity.ts" source="www/src/examples/date-divider/activity.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { DateDivider, groupByDay } from "./ui/uicontext/components/DateDivider.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	wrap: { inlineSize: "min(100%, 28rem)" },
	list: { display: "grid", gap: space.xs, margin: 0, padding: 0, listStyle: "none", paddingBlockEnd: space.sm },
	row: { display: "flex", justifyContent: "space-between", gap: space.md, fontSize: font.sm },
	time: { flexShrink: 0, fontSize: font.xs, color: color.muted, fontVariantNumeric: "tabular-nums" },
})

const now = "2026-12-04T16:30:00Z"
const timeZone = "America/New_York"
const clock = new Intl.DateTimeFormat("en-US", { timeZone, hour: "numeric", minute: "2-digit" })

// what happened to an issue, newest first, in New York time: 01:00 UTC on the 4th is still the 3rd there
const events = [
	{ id: "e1", at: "2026-12-04T15:10:00Z", text: "Ada Okafor closed the issue" },
	{ id: "e2", at: "2026-12-04T01:00:00Z", text: "Deploy 3f9a2c reached production" },
	{ id: "e3", at: "2026-12-03T14:30:00Z", text: "Tomás García linked a pull request" },
	{ id: "e4", at: "2026-11-30T16:00:00Z", text: "Priya Raman set priority to High" },
	{ id: "e5", at: "2026-11-18T13:20:00Z", text: "Wei Chen opened the issue" },
]

export const IssueActivity = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.wrap)).children(
		groupByDay(events, (e) => e.at, { now, timeZone, locale: "en-US" }).map((day) =>
			h.section.key(day.key).children(
				DateDivider(h, { label: day.label, align: "start" }),
				h.ul.attrs(sx(styles.list)).children(
					day.items.map((e) => h.li.key(e.id).attrs(sx(styles.row)).children(h.span.children(e.text), h.span.attrs(sx(styles.time)).children(clock.format(new Date(e.at)))))),
			)),
	)
```

## API reference

### DateDivider (view function)

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `label` (required) | `string` | The day: from `dayLabel`, or any words. |
| `align` | `"center" \| "start"` | The label at the start of the line rather than in the middle. |
| `sticky` | `boolean` | Sticks to the top of its scrolling feed, on a pill, while the day's items pass under it. |
| `style` | `Style` | — |

### Day (view function)

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `now` (required) | `string` | The instant it is now, ISO: days are counted back from its day. |
| `timeZone` | `string` | The reader's IANA time zone, such as "Europe/London": it decides which day an instant falls on. |
| `locale` | `string` | Writes weekdays and dates in this language. |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/date-divider
```

With npm: `npx shadcn@latest add checkfu/uicontext/date-divider`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/date-divider`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/date-divider`.

It writes these files:

- `src/ui/uicontext/components/DateDivider.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/DateDivider.ts](https://github.com/checkfu/uicontext/blob/main/src/DateDivider.ts)

## Related

- [Button](https://uicontext.com/docs/components/button.md) (`button`): A button, and a link that looks like one, in every tone and three sizes.
- [Toggle](https://uicontext.com/docs/components/toggle.md) (`toggle`): A button that stays pressed, such as Bold or Pin.
- [Toggle Group](https://uicontext.com/docs/components/toggle-group.md) (`toggle-group`): Buttons that stay pressed and share one value, such as text styles.
- [Input](https://uicontext.com/docs/components/input.md) (`input`): Text inputs, selects and textareas in a labeled field with a hint and an error, and their styles for controls you lay out yourself.
- [Status](https://uicontext.com/docs/components/status.md) (`status`): Status badges and tags for runs and records.
- [Glyphs](https://uicontext.com/docs/components/glyphs.md) (`glyphs`): Small marks for status, priority, color and people.
