# `calendar@1`: calendar occurrences and tracked time

Version **1.1.0** · published 2026-12-02 · MIT · boards: time-audit · [changelog](../CHANGELOG.md)

One row of `events` is one **occurrence** on one calendar: a repeating meeting is expanded by the connector inside its
import window, so a weekly 1:1 over 16 weeks is 16 rows. `event_days` cuts every occurrence at the local midnights of
the person's time zone, so a metric adds up a day, a week or an hour of the day without expanding a repeat or doing
time-zone arithmetic. Time Audit reads it; a week planner and Days Abroad's flight mapper will (wave 2).

## Conventions
- **Occurrences, expanded once.** Connectors expand RRULE, RDATE and EXDATE, and apply overrides (a moved or
  cancelled instance, matched by its RECURRENCE-ID as an instant), inside `[meta.window_start, meta.window_end)`.
  Occurrences are generated in the wall-clock time of the event's own zone, so a 10:00 meeting stays at 10:00 across a
  daylight-saving change; its UTC instant moves. DTSTART is always the first occurrence and counts toward COUNT.
- **Times.** `start_utc` / `end_utc` are ISO 8601 UTC (`end` exclusive) and `tz` is the zone the event was written in.
  All-day events run from local midnight to local midnight in `meta.timezone` (the person's zone) and have
  `all_day = 1`. Floating times (no zone in the file) are read in `meta.timezone`.
- **Days.** `event_days.day` is the local date in `meta.timezone`; `start_s` / `end_s` are **wall-clock** seconds after
  local midnight (86400 = runs to midnight), and `duration_s = end_s - start_s`. Every cut (a day, a week, an hour of
  the day, working hours) uses these wall-clock seconds, so totals always reconcile; on the two daylight-saving days a
  year, an event that spans the changed hour is counted by the clock on the wall, not by elapsed time.
- **What counts as busy time.** Every occurrence is kept. `excluded` is NULL when it counts, else the first reason
  that applies, in this order: `cancelled` (status), `declined` (the person's response), `duplicate` (the same
  instance is on another of their calendars), `all_day`, `free` (shows as available), `ignored` (the person's rule).
  Tentative and unanswered invitations count: calendars show them as busy.
- **Duplicates.** The same UID, instance and start on two calendars (an invitation that is on the work calendar and on
  a shared one) counts once: `duplicate_of` names the copy that counts (the person's own calendar first, then the one
  they accepted on, then a work calendar, then by `calendar_id`).
- **Categories and focus.** `categories` are the person's own (each has a `kind`: meeting, focus, personal, other,
  time_off). `event_rules` are their rules in order (first match wins); an event no rule matches gets a default by
  calendar kind and the number of people. **Focus** has one meaning here: time the person booked for focused work
  (`focus = 1`, from a rule or a focus category). Free gaps in a working day are not stored: boards compute them from
  busy time and the working hours in `meta`.
- **People.** `attendees_n` counts the people on the invitation (attendees plus the organizer; rooms and resources left
  out) and `declined_n` the invitees who declined. Addresses and descriptions are read to find the person's own
  response and a video-call link, and are **never stored**.
- **IDs.** `event_id` is the first 16 hex of sha1(`calendar_id|uid|recurrence_id|start`), with `recurrence_id` and the
  start written as in the table (all-day: the start date), so re-importing the same files gives the same ids.
  `series_id` is the first 16 hex of sha1(`calendar_id|series uid`) on repeating events, where the series uid is the
  UID without Google's "this and following" split suffix (`abc_R20261015T170000@google.com` → `abc@google.com`), so a
  series edited part-way (new people from October on) stays one series. `calendar_id` comes from the
  calendar's name (or the person's own id), never from the order of files.
- **Provenance:** `source`, `source_ref` (file, zip member and line), `imported_at` (left out of `meta.data_hash`).
- meta required keys: `schema`, `schema_version`, `as_of`, `data_hash`, `timezone`. Recommended (checked at `warn`):
  `source_built_at`, `window_start`, `window_end`, `week_start`, `work_days` (bit mask Mon=1 .. Sun=64),
  `work_start_s`, `work_end_s`.

## Tracked time (1.1)

`time_entries` holds completed work or volunteer shifts. Client Projects & Hours, Project Portfolio and Volunteer Hours
use it for actual time. Project budgets and coverage targets come from the board's own inputs. Proposal Pipeline can
use project time summaries for estimates when explicitly connected.

- **Rows and dates.** One row per completed record. Preserve the export's local date when it only supplies a date
  and duration. If both instants are known, set `tz` to an IANA zone and `day` to the local start date in that zone.
  An overnight row is grouped under its start day. Duration is elapsed whole seconds, including across daylight-saving
  changes. When both instants are known, duration must agree with the elapsed interval within one second. Calendar
  occurrences retain their separate wall-clock rules.
- **Source identity.** Build `entry_id` from `source:source_account:key`. Use a stable account or workspace alias
  made of letters, digits, dot, underscore or hyphen. Use the source's own record ID for `key` when available. Otherwise
  hash the source's normalized natural key (person, client, project, task and date/interval or duration) and append an
  occurrence counter for identical records. Source filenames, line numbers, import times and amounts do not define
  identity. Deduplicate repeated exports from the same account only.
- **Grouping and privacy.** Client, project and task IDs are scoped to the source and account. Labels are for display.
  Use an opaque `person_id`, including for volunteers. Keep names and email addresses out of that field.
- **Billing.** `billable` describes whether the source says the time can be billed. `billed` describes whether the source
  says it has been invoiced. Unknown is NULL in either column. An invoiced entry is billable. Hourly rates are
  non-negative major currency units per hour, paired with a three-letter ISO 4217 currency. NULL means no rate was
  supplied. Zero records an explicit zero. Group totals by currency unless the board has explicit conversion inputs.
- **Provenance.** Preserve the connector ID, account alias, source object ID or file and line, and UTC import instant.
  Record confidence for inferred values. Keep import timestamps out of the data hash.

## Sources that fill it
| Source | Lane | Fills |
|---|---|---|
| Google Calendar: Settings → Import & export → Export (a .zip with one .ics per calendar), or Google Takeout | 1 | calendar event tables (`source = ics-google`) |
| Apple Calendar: select a calendar → File → Export → Export… (.ics) | 1 | calendar event tables (`source = ics-apple`) |
| Outlook / Microsoft 365: Outlook on the web → Settings → Calendar → Shared calendars → Publish (an .ics link you download yourself) | 1 | calendar event tables (`source = ics-outlook`); Windows zone names map to IANA |
| Toggl Track, Harvest and Clockify: download a detailed time report as CSV | 1 | `time_entries` (`toggl-csv`, `harvest-csv`, `clockify-csv`) |
| Project-tool time log or signup sheet exported to CSV | 1 | `time_entries` (`project-csv` or `sheet-csv`) |
| A calendar's private iCal address (secret URL) | 2 (wave 2) | the same, fetched by a local connector with the URL kept in the keychain |

## Compatibility
- A board that declares `calendar@1 >=1.0` keeps working on any later 1.x database.
- Boards that read `time_entries` declare `calendar@1 >=1.1`. An empty table means no tracked entries were imported.
  An existing 1.0 database can still conform without it. The [minor upgrade](../migrations/README.md) adds the table
  without changing calendar records.
- Remixes that add only metrics, pages and `x_<owner>_` tables survive every minor.
- Breaking changes go to `calendar@2` with a migration and `metrics-codemod.py` (see `../../README.md`, Semver).
- Planned minors: a `travel` category kind (flights and hotels for Days Abroad), per-event zones for people who travel.

## Fields

<!-- fields:begin (generated from schema.sql by spec/build.py; edit the DDL comments) -->

### `meta` (required table)

Key/value facts about this database. Required: schema, schema_version, as_of, data_hash, timezone (the person's IANA time zone: event_days are cut at its midnights). Recommended (checked at warn): source_built_at (ISO 8601 UTC), window_start and window_end (YYYY-MM-DD, end exclusive: the days the connector expanded and imported), week_start (mon..sun), work_days (bit mask Mon=1 .. Sun=64), work_start_s and work_end_s (seconds after local midnight).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `key` | TEXT | no |  |
| `value` | TEXT | no |  |

### `calendars` (required table)

The calendars the events came from (one per exported .ics, or per member of a Google export zip).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `calendar_id` | TEXT | **yes** | from the calendar's name (or the person's own id), never from file order, e.g. work |
| `name` | TEXT | **yes** | display name (X-WR-CALNAME or the person's name for it) |
| `owner_self` | INTEGER | no | 1 = the person's own calendar, 0 = someone else's they subscribe to or share |
| `kind` | TEXT (vocab `calendar_kinds`) | no | work \| personal \| shared \| subscribed (vocab calendar_kinds) |
| `color_idx` | INTEGER | no | stable index into the chart palette tokens |
| `tz` | TEXT | no | the calendar's default zone as the export states it (X-WR-TIMEZONE), information only |
| `source` | TEXT (vocab `sources`) | no | connector id: ics-google \| ics-apple \| ics-outlook \| ics (vocab sources) |
| `source_ref` | TEXT | no | the file (and zip member) it came from |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import (left out of meta.data_hash) |

### `categories`

The person's categories: each says what kind of time it is.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `category` | TEXT | **yes** | the person's name for it, e.g. 1:1s, Customer calls, Focus |
| `kind` | TEXT (vocab `category_kinds`) | **yes** | meeting \| focus \| personal \| other \| time_off (vocab category_kinds) |
| `color_idx` | INTEGER | no | stable index into the chart palette tokens |
| `ord` | INTEGER | no | display order (1 = first) |
| `description` | TEXT | no | why it matters, in the person's words |

### `event_rules`

The rules that sorted events into categories (from the person's rules file), first match wins.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `rule_id` | TEXT | **yes** | the rule's id: its own id: or a hash of what it matches (never its position) |
| `ord` | INTEGER | **yes** | order in the file (1 = tried first) |
| `match` | TEXT | **yes** | JSON of what it matches: title / location (patterns), calendar, min_people, max_people, organizer, recurring, online, all_day |
| `category` | TEXT | no | the category it gives (NULL with ignore) |
| `focus` | INTEGER | no | 1 = the events it matches are focus time the person booked |
| `ignore` | INTEGER | no | 1 = the events it matches are not counted (excluded = ignored) |
| `source_ref` | TEXT | no | where the rule is, e.g. data/rules.yaml:rules[3] |

### `events` (required table)

One occurrence of an event inside the import window. Every occurrence is kept, also the ones that are not busy time; `excluded` says why one does not count (NULL = it counts).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `event_id` | TEXT | **yes** | first 16 hex of sha1(calendar_id\|UID\|RECURRENCE-ID\|start); RECURRENCE-ID and start as written in recurrence_id and start_utc (all-day: the start date) |
| `calendar_id` | TEXT | **yes** | the calendar it is on |
| `uid` | TEXT | no | the source's UID (several calendars can hold the same UID) |
| `recurrence_id` | TEXT | no | the instance's original start as a UTC instant (all-day: its date); NULL for an event that does not repeat |
| `start_utc` | TEXT (instant) | **yes** | ISO 8601 UTC instant it starts; all-day: local midnight of its first day in meta.timezone |
| `end_utc` | TEXT (instant) | **yes** | ISO 8601 UTC instant it ends (exclusive); all-day: local midnight after its last day |
| `tz` | TEXT | **yes** | the zone its times were written in: an IANA name, UTC, or the source's TZID when the file defined a zone with no IANA name; floating and all-day times use meta.timezone |
| `all_day` | INTEGER | **yes** | 1 = an all-day (date-only) event |
| `title` | TEXT | no | SUMMARY |
| `location` | TEXT | no | LOCATION as written (may be a room or an address) |
| `is_online` | INTEGER | no | 1 = a video-call link in the location, URL, description or conference fields (the link itself is not kept) |
| `organizer_self` | INTEGER | no | 1 = the person organised it, 0 = someone else, NULL = unknown (no address for the person, or no organizer) |
| `attendees_n` | INTEGER | no | people on the invitation (attendees plus the organizer, rooms and resources left out); 0 = nobody listed |
| `declined_n` | INTEGER | no | invitees other than the person who declined this occurrence |
| `response` | TEXT (vocab `responses`) | no | the person's answer: accepted \| tentative \| declined \| needs_action \| none (vocab responses) |
| `status` | TEXT (vocab `statuses`) | no | confirmed \| tentative \| cancelled (vocab statuses) |
| `transparency` | TEXT (vocab `transparency`) | no | busy \| free (vocab transparency): free = shows as available |
| `recurring` | INTEGER | **yes** | 1 = an occurrence of a repeating event (including a moved one) |
| `series_id` | TEXT | no | first 16 hex of sha1(calendar_id\|series UID) for repeating events: the UID without Google's "this and following" split suffix (_R20261015T170000), so a series edited part-way stays one series |
| `category` | TEXT | no | the person's category (categories.category), from the first rule that matched or the defaults |
| `focus` | INTEGER | no | 1 = focus time the person booked (a rule with focus: true, or a category of kind focus) |
| `rule_id` | TEXT | no | the rule that set the category; NULL = a default |
| `duplicate_of` | TEXT | no | event_id of the copy that counts when the same instance (UID, recurrence, start) is on several calendars |
| `excluded` | TEXT (vocab `excluded_reasons`) | no | NULL = counts as busy time; else the first reason that applies, in this order: cancelled \| declined \| duplicate \| all_day \| free \| ignored (vocab excluded_reasons) |
| `source` | TEXT (vocab `sources`) | no | connector id (vocab sources) |
| `source_ref` | TEXT | no | file (and zip member) and the line where the VEVENT is |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import (left out of meta.data_hash) |
| `confidence` | TEXT | no | rule \| default: how the category was decided |

### `event_days` (required table)

Each event cut at the local midnights of meta.timezone: one row per event per day it touches, inside the window. Wall-clock seconds, so a meeting from 09:00 to 10:00 is 3600 seconds even on a daylight-saving day.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `event_id` | TEXT | **yes** | the event |
| `day` | TEXT (date) | **yes** | local date (YYYY-MM-DD) in meta.timezone |
| `start_s` | INTEGER | **yes** | wall-clock second of the day it starts on that day (0 = midnight) |
| `end_s` | INTEGER | **yes** | wall-clock second of the day it ends on that day (86400 = runs to midnight) |
| `duration_s` | INTEGER | **yes** | end_s - start_s |

### `time_entries`

Optional tracked time entries (1.1). Each row is a completed time record from one source account. Report by day in the entry's own local zone, and measure elapsed seconds. Calendar events and wall-clock slices are separate.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `entry_id` | TEXT | **yes** | stable source:source_account:key, e.g. toggl-csv:studio:tg-401 |
| `day` | TEXT (date) | **yes** | source date for a date-only record; otherwise the local start day in tz, YYYY-MM-DD |
| `duration_s` | INTEGER | **yes** | non-negative elapsed seconds, e.g. 5400 for 90 minutes |
| `start_utc` | TEXT (instant) | no | ISO 8601 UTC start, NULL when the export gives only a date and duration |
| `end_utc` | TEXT (instant) | no | ISO 8601 UTC end (exclusive); set with start_utc or left NULL with it |
| `tz` | TEXT | no | IANA zone for the source's local time, required when both instants are known |
| `client_id` | TEXT | no | stable source-account client id |
| `client` | TEXT | no | display label, e.g. Prism Workshop |
| `project_id` | TEXT | no | stable source-account project or program id |
| `project` | TEXT | no | display label, e.g. Winter mural |
| `task_id` | TEXT | no | stable source-account task id |
| `task` | TEXT | no | display label, e.g. Sketching |
| `person_id` | TEXT | no | source-scoped opaque person id; keep names and email addresses out of this field |
| `billable` | INTEGER | no | 1 = billable, 0 = non-billable, NULL = unknown |
| `billed` | INTEGER | no | 1 = already invoiced, 0 = known to be uninvoiced, NULL = unknown |
| `hourly_rate` | REAL | no | non-negative major currency units per hour, e.g. 85.50; NULL when missing |
| `currency` | TEXT (currency) | no | ISO 4217 currency of hourly_rate, e.g. USD; NULL with missing rate |
| `source` | TEXT (vocab `time_sources`) | **yes** | connector id (vocab time_sources) |
| `source_account` | TEXT | **yes** | stable account or workspace alias used as the id namespace, e.g. studio |
| `source_ref` | TEXT | **yes** | source object id, or file and line, e.g. december.csv:7 |
| `imported_at` | TEXT (instant) | **yes** | ISO 8601 UTC import instant, excluded from meta.data_hash |
| `confidence` | TEXT | no | rule \| default \| detected \| manual when a value is inferred; NULL for source values |

### `data_issues`

What the importer could not read or decided: events skipped, rules it cannot follow, unknown zones, duplicates.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `issue_id` | TEXT | **yes** | stable id |
| `severity` | TEXT (vocab `severities`) | **yes** | info \| warn \| error (vocab severities) |
| `kind` | TEXT | **yes** | rows_skipped \| rule_unsupported \| unknown_tz \| duplicate_uid \| duplicate \| outside_window \| no_self \| ... |
| `title` | TEXT | **yes** | one line |
| `detail` | TEXT | **yes** | what and where (file:line), never an event's description |
| `source_ref` | TEXT | no | file, or file:line |
| `handling` | TEXT | **yes** | what the importer did about it |

### `annotations`

Notes on metrics and pages (platform table, as finance@2). Numbers only through {{metric:...}} placeholders.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `annotation_id` | TEXT | **yes** | stable id |
| `target` | TEXT | **yes** | metric id or page id |
| `kind` | TEXT | **yes** | note \| caveat \| flag \| decision \| open_item |
| `body` | TEXT | **yes** | the note text |
| `author` | TEXT | no | person or assistant |
| `source_ref` | TEXT | no | where it came from |
| `created_at` | TEXT | no | ISO 8601 instant |
| `data_hash` | TEXT | no | hash of the cited metric values when written (stale when they change) |
| `status` | TEXT | no | active \| stale \| retired |

### `metric_registry`

| Field | Type | Required | Meaning |
|---|---|---|---|
| `metric_id` | TEXT | **yes** | e.g. time.weekly |
| `version` | INTEGER | no | the metric's own version |
| `unit` | TEXT | no | rows \| hours \| count \| pct ... |
| `params` | TEXT | no | comma list of parameters it honours |
| `description` | TEXT | no | the @desc line |
| `sql` | TEXT | no | expanded SQL |
| `test` | TEXT | no | the @test line (check that covers it) |

<!-- fields:end -->
