# Dates and retention

## Dates

`date` makes a history readable by period. It's a rule, read on the row as it's kept, so it can use only what `fields` keeps (after `remove_after`). Its value becomes the row's `date`. A plain path works (`"date": "date"`), and so does any rule that gives a date, such as the newest Delivered event's date in the [Parcel source](https://legatobar.com/docs/history-collect.md#collect-on-the-page-that-fetches).

A date is one of three kinds:

| Kind | Written like | Kept as | In a period |
| --- | --- | --- | --- |
| `day` | `2026-10-26`, "November 6, 2026", `02.11.2026`, `11/02/2026` | The date | When it's one of the period's days |
| `wall`, a time with no zone | `2026-11-06 10:05:00`, "Friday, November 6, 2026 10:05 AM" | The printed date and time, as printed | By its printed date, as a `day` |
| `moment`, an instant | `2026-11-06T16:46:00-08:00`, `…Z`, "November 2, 2026 03:14 PM EST", Unix seconds | The instant, in UTC | From midnight at the start of the period's first day to midnight after its last, in the Mac's time zone |

- **A wall time is never moved to the Mac's zone.** "November 6, 2026 4:46 PM" is in the 6th whichever Mac reads it, wherever it is. Parcel's dates are wall times.
- **Carriers' own words are read with fixed rules,** not the Mac's language settings: a date with slashes is month first (`11/02/2026` is November 2) and one with dots is day first (`02.11.2026` is November 2). Times like "3:14pm" and "3:14 p.m." are read as "3:14 PM".
- **A number is Unix time:** seconds, or milliseconds from 100,000,000,000 up. Digits in text aren't read as one.
- **A date that can't be read** (words like "next Tuesday", or text over 80 characters) leaves the row undated. So does an item where the rule finds nothing.

### `time_zone`

When the service's times have no zone but you know which zone they're in, say so, and they're kept as moments:

```json
"date": "reading_time", "time_zone": "America/Los_Angeles"
```

- A time the clocks pass twice when they go back (1:30 AM on the night daylight saving time ends) is the first one.
- A time the clocks skip when they go forward (2:30 AM on the night it starts) moves forward by the gap: 2:30 becomes 3:30.
- `time_zone` is a zone name from the IANA list. An unknown one stops the page loading: `time_zone is a zone name like America/Los_Angeles`.

### `date_range`

A service that sends placeholder dates, like `1970-01-01` or a year far ahead, can put rows in the wrong period. `date_range` keeps only dates within it as dates, inclusive:

```json
"date_range": { "from": "2000-01-01", "to": "+1y" }
```

Each bound is a day, or days or years from today: `+30d`, `-10y` (a sign, 1 to 4 digits, and `d` or `y`). A date outside the range leaves the row undated; the row is still kept.

### Dates in cards

Three rules work on any source, kept rows or not:

- **`{ "date": rule }`** gives the rule's value as a date, written one way: `2026-11-04` for a day, `2026-11-06T16:46:00` for a wall time (no zone), `2026-11-07T00:46:00Z` for a moment. Words it can't read leave the result missing, so `default` applies.
- **`{ "days_between": [rule, rule] }`** counts whole calendar days from the first date to the second, negative when the second is earlier. Days and wall times count by their printed date; moments by the day they fall on in the Mac's time zone. From "Picked up" on October 26 to "Delivered" on November 4 is 9.
- **`"as": "date"`** in a `sort` compares values as dates, so "November 10" comes after "November 9". Values that aren't dates go last, in either order.

```json
{ "days_between": [
  { "date": { "first": "date", "of": "row.events", "where": { "path": "event", "contains": "Picked up" },
              "sort": { "by": "date", "as": "date" } } },
  "date" ] }
```

Read on each of `kept.rows`, this is the days from a package's first "Picked up" event to the row's own date. Inside `kept.rows`, the item's fields are under `row.`, and the row's date is `date`.

## How long rows are kept

`keep.for` is how long a row stays, from what `keep.clock` counts:

| `clock` | A row's age counts from |
| --- | --- |
| `date_or_last_seen` (the default) | The later of its date and the last time an answer had it. A row stays while the service keeps sending it, and for `for` after both. |
| `date` | Its date. An undated row counts from when it was last seen. A row already older than `for` when it arrives isn't kept: it's counted as already past retention. |
| `last_seen` | The last time an answer had it, or it was added. |

- Legato removes rows past their time each time it keeps an answer, and at launch and once a day for every history, whether or not anything is collecting.
- **Rows added from outside count from when they're added,** unless the clock is `date`. To import old rows and have them age by their own dates, use `"clock": "date"`.
- Changing `keep` applies to every row from the next cleanup, old histories included.

### Limits

| | Limit |
| --- | --- |
| One row | 16 KB (16,384 bytes) of JSON, as kept. A larger one isn't kept, and is counted as rejected. |
| One answer, or one `rows add` | 2,000 items and 8 MB (8,388,608 bytes). A larger answer isn't kept at all; a larger `rows add` is refused. |
| The current history of one dataset | 20,000 rows and 50 MB (52,428,800 bytes) |
| Every history on the Mac, together | 500 MB (524,288,000 bytes) |

- **At a history's limit,** the oldest rows by its clock make way, in the same step, and are counted as pruned for space. The rows arriving always land. A batch that doesn't fit by itself is refused.
- **At the limit for every history,** a batch that would make storage grow isn't kept at all, including its updates to rows already kept. A batch that doesn't grow storage still is. Settings shows “History storage is full. This collection batch is paused, including updates to existing records. Delete old history to resume.” Delete old histories, or a history you don't need, to make room; the note clears after a successful collection.
- Sizes are the rows' JSON. The database, its indexes and its journal take more space on disk than that.

The other limits are in [Limits](https://legatobar.com/docs/limits.md#history).

