Skip to content

feat(export): date range for the JSON exports - #857

Open
RaoufGhrissi wants to merge 1 commit into
ActivityWatch:masterfrom
RaoufGhrissi:master-export-date-range-abgh
Open

RaoufGhrissi wants to merge 1 commit into
ActivityWatch:masterfrom
RaoufGhrissi:master-export-date-range-abgh

Conversation

@RaoufGhrissi

Copy link
Copy Markdown

The JSON exports can't be limited to a period today: /api/0/export and /api/0/buckets/<id>/export always return a bucket's whole history, while the CSV export already accepts start/end. This adds the same optional start and end (RFC 3339) to both JSON exports.

  • Events overlapping the range are returned cut to it, with the same rules as /events and the CSV export.
  • Without start/end, the export is unchanged, the whole history, so existing clients keep working.
  • An invalid or out-of-range date answers 400, like /events. An empty range (start after end) exports the buckets without events.

The range goes from the endpoints through Datastore::export_to_file to the streaming serializer in aw-datastore/src/export.rs, replacing its fixed "everything" window. The export still streams row by row.

Tests

  • ranged_json_export_matches_get_events_for_the_same_range: the ranged export equals get_events for the same range, for one bucket and for all.
  • json_export_with_an_empty_range_has_no_events.
  • json_exports_take_a_date_range (API): both endpoints, an event over midnight cut to the range, one side only, no range, and bad dates answering 400.

cargo test -p aw-datastore -p aw-server passes, and the changed lines are clippy-clean.

The web UI side, an export dialog with this date range, is a separate PR in aw-webui.

/api/0/export and /api/0/buckets/<id>/export take optional start and end
(RFC 3339), like the CSV export already did: the events overlapping the
range, cut to it, as /events returns them. Without them, the export is the
whole history, unchanged. Invalid dates answer 400, an empty range exports
the buckets without events.
@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Adds optional RFC 3339 start and end dates to both JSON export endpoints.

  • JSON exports can be limited to a date range.

No actionable issues were found. Tests were reviewed but not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[JSON export request] --> B[Parse optional dates]
    B -->|Invalid date| C[400 JSON response]
    B -->|Valid dates| D[Export responder]
    D --> E[Datastore worker]
    E --> F[Select and clip overlapping events]
    F --> G[Write JSON rows to temporary file]
    G --> H[Stream download]
Loading

Reviews (1) · Last reviewed commit: "feat(export): date range for the JSON ex..." · Reviewed by Greptile

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Thanks! Matching the CSV export's start/end on the JSON exports is a good, consistent API. To get it merged:

I'll do a full review as soon as CI has run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants