---
title: "Recipe: dates and days"
description: "The date is time.epochAtZero + performanceNow(), with the reserved exactTime() source."
modificationDate: "2026-11-14"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: dates and days

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/dates-and-days: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

The date is `time.epochAtZero + performanceNow()`, with the reserved `exactTime()`
source. A day is a key, `"2026-03-14"`, in the person's own time zone.

```prompt Show dates and days in my app
Make the Exact app in this folder read the date, and keep each day as a key in the time zone of the person who uses the app. Use https://github.com/expo/exact/blob/main/docs/recipes/dates-and-days.md as the source for each step. The Exact checkout has the same page at docs/recipes/dates-and-days.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say what the app dates and which days it keeps (a habit log, a due date, entries by day), propose it from what the app does and ask me before you write code.
3. In app.contract, read `exactTime()` as a resource with a `shape Time` that has `epochAtZero` and `utcOffset`. The date is `time.epochAtZero + performanceNow()`.
4. Keep the time in a state that a `task` writes, as the recipe does with `every(60000, step)`. A derive of the clock does not update by itself, and `performanceNow()` is 0 at each launch.
5. Keep a day as the key `formatDate(shown, time.utcOffset, "iso")`, and compare keys as text. An action that writes a day reads the clock itself: it takes `let at = time.epochAtZero + performanceNow()` and keys `formatDate(at, time.utcOffset, "iso")`. Do not key the entry by the ticked `now`: it can lag a minute, and an entry at midnight lands on yesterday.
6. Write a day's label with `formatDay`, never with a comparison such as `day == today`. Its modes are `"day"`, `"day-time"`, `"list"` and `"section"`. Label an `input type="date"` value with `formatDate(due, 0, "medium")`.
7. Add the recipe's two tests to app.test.contract, each with `epoch` and `time-zone` pinned. One moves the clock past local midnight (`clock +3600000`) and expects the new day. One writes an entry 30 s after midnight, before the tick, and expects the new day's key.
8. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 9) and report it; do not keep trying.
9. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
10. Tell me which dates and days the app keeps, what the tests and checks reported, and the launch command for each target platform. `utcOffset` is the zone's offset now: tell me each label that can miss an hour across a DST change.
```

```contract
shape Time
  epochAtZero: number
  utcOffset: number

component Habit
  state now = 0
  state doneDays = []
  state lastAt = 0
  resource time = exactTime() as shape Time
  derive shown = time.epochAtZero + now
  derive today = formatDate(shown, time.utcOffset, "iso")
  derive yesterday = formatDate(shown - 86400000, time.utcOffset, "iso")
  task tick mount
    every(60000, step)
  action step
    now = performanceNow()
  action markDone
    let at = time.epochAtZero + performanceNow()
    now = performanceNow()
    doneDays = doneDays.concat([formatDate(at, time.utcOffset, "iso")])
    lastAt = at
  view
    column padding=16 gap=8
      text formatDate(shown, time.utcOffset, "medium") role="heading" aria-level=2 testId="today"
      if doneDays.includes(today)
        text "Done today" testId="status"
      else if doneDays.includes(yesterday)
        text "Done yesterday" testId="status"
      else
        text "Not done yet" testId="status"
      if lastAt > 0
        text `Last done ${formatDay(lastAt, shown, time.utcOffset, "day-time")}` testId="last"
      button press=markDone disabled=doneDays.includes(today) buttonStyle="filled" testId="done"
        text "Mark Done"
```

```contract-test
test "the day turns over at local midnight"
  epoch "2026-03-15T06:30:00Z"
  time-zone "America/Los_Angeles"
  expect text "today" == "Mar 14, 2026"
  tap "done"
  expect text "status" == "Done today"
  clock +3600000
  expect text "today" == "Mar 15, 2026"
  expect text "status" == "Done yesterday"
  expect text "last" == "Last done Yesterday at 11:30 PM"

test "an entry made 30 s after midnight, before the tick, is the new day's"
  epoch "2026-03-15T06:59:50Z"
  time-zone "America/Los_Angeles"
  clock +40000
  expect text "today" == "Mar 14, 2026"
  tap "done"
  expect state doneDays.0 == "2026-03-15"
  expect text "status" == "Done today"
```

- **The write reads the clock itself.** The ticked `now` can lag a minute, so an
  entry keyed by `today` at midnight lands on yesterday: the action takes
  `let at = time.epochAtZero + performanceNow()` and keys `formatDate(at, time.utcOffset, "iso")`.
- A derive of the clock doesn't update by itself: keep the time in state a
  `task … every` writes; `performanceNow()` is 0 at each launch.
- `"iso"` is the day key, compared as text. A label is `formatDay(then, shown, offset,
  mode)`, never `day == today ? "Today" : …`: `"day"` is `Today`, `Tomorrow` or `Mar 14, 2026`;
  `"day-time"` adds ` at 11:30 PM`; `"list"` is Mail's; `"section"` a chat's separator.
- Label an `input type="date"` value with `formatDate(due, 0, "medium")`.
  A `YYYY-MM-DD` key keeps its day at any valid offset; invalid dates print `""`.
- `utcOffset` is the zone's offset now: `shown - 86400000` and `formatDay` can miss an hour
  across a DST change. Tests pin `epoch` and `time-zone`; the default is 2026-01-01 UTC.
