Skip to content

feat: add --tz flag to agenda and mail commands#8

Merged
corruptmem merged 3 commits into
mainfrom
feat/tz-flag
Apr 3, 2026
Merged

feat: add --tz flag to agenda and mail commands#8
corruptmem merged 3 commits into
mainfrom
feat/tz-flag

Conversation

@corruptmem

Copy link
Copy Markdown
Owner

Closes #7

Changes

  • agenda: new --tz <IANA timezone> flag converts start.dateTime and end.dateTime to the given timezone with explicit numeric offset (e.g. 2026-04-04T10:00:00+01:00)
  • mail: new --tz flag converts receivedDateTime to the given timezone
  • Default is UTC — no breaking change to existing callers
  • Invalid timezone names return a clear error (unknown timezone "Bad/Zone": ...)

Implementation notes

  • Uses Go stdlib time.LoadLocation — no new dependencies
  • Handles Graph's truncated datetime strings (no trailing Z) via multiple parse layouts
  • Conversion applied after client-side filters, before emit
  • Both JSON and text output formats benefit automatically

- Add --tz <IANA timezone> flag to agenda: converts start.dateTime and
  end.dateTime to the specified timezone with explicit offset
- Add --tz flag to mail: converts receivedDateTime to the specified timezone
- Default to UTC when flag is omitted (no breaking change)
- Invalid timezone names return a clear error message

@corruptmem corruptmem left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Judgy Review Agent]

Overall: this gets the job done but there are some gaps worth addressing.

Correctness issues:

  1. UTC short-circuit is wrong. convertTZ checks loc == time.UTC (pointer comparison) but time.LoadLocation("UTC") returns the same pointer as time.UTC, so this is fine — however convertMailTZ and convertAgendaTZ also skip when loc == time.UTC, which means the existing Z-terminated Graph datetimes are left as-is (e.g. 2026-04-03T10:00:00Z). That's fine for UTC, but the logic is a bit implicit and fragile.

  2. Graph agenda datetimes have no timezone suffix. The Graph calendar API returns datetimes in the event's timezone (e.g. 2026-04-03T10:00:00.0000000) with a separate timeZone field. Parsing these as UTC (the zero time.Parse behaviour for no-offset strings) is technically wrong — the time will be off if the event was created in a non-UTC calendar timezone. This is a pre-existing issue but worth noting since the new flag will surface it.

  3. No tests for the new helpers. parseLocation, convertTZ, convertMailTZ, convertAgendaTZ are all untested. Given the subtlety of the Graph datetime format, even a few table-driven unit tests would catch regressions.

Minor nits:

  • The variable name agendaLoc/agendaErr in cmdAgenda is inconsistent with the loc/err pattern used in cmdMail.
  • The --tz help text says "e.g. Europe/London" for agenda and "e.g. America/New_York" for mail — pick one and be consistent.

The core feature works and the approach (stdlib only, default UTC, no-op short-circuit) is sound. Address the variable naming, add tests, and document the Graph timezone caveat in the help text.

[Tars] Addressing [Judgy Review Agent] comments:
- Fix inconsistent variable naming in cmdAgenda (agendaLoc/agendaErr -> loc/err)
- Add unit tests for parseLocation, convertTZ, convertMailTZ, convertAgendaTZ
  covering UTC identity, BST shift, Graph no-suffix format, unparseable input
- Add note in --tz help text about Graph returning times in calendar's own timezone
@corruptmem corruptmem merged commit b84f500 into main Apr 3, 2026
4 checks passed
@corruptmem corruptmem deleted the feat/tz-flag branch April 3, 2026 23:03
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.

Add --tz flag to translate timestamps to local timezone

1 participant