Skip to content

Timezone handling in activity shortcut tools (overdue / upcoming) #12

Description

@warwickpalm

Problem

The pipedrive_my_overdue_activities and pipedrive_my_upcoming_activities tools use a UTC-based today() helper for client-side filtering:

function today(): string {
  return new Date().toISOString().split("T")[0];
}

This causes incorrect results for users outside UTC:

  • Positive offsets (e.g. UTC+12 Auckland): an activity due "yesterday" in user local time won't be flagged as overdue for several hours until UTC catches up
  • Negative offsets (e.g. UTC-8 Los Angeles): an activity due "today" in user local time gets flagged as overdue prematurely (once UTC rolls to the next day)

The problem compounds for timed activities, which are returned from the Pipedrive API as UTC timestamps (due_date + due_time combined). A timed activity at 9am tomorrow local could have due_date: "<today UTC>" in the response, so even a user-local-TZ fix to today() alone wouldn't handle it correctly.

Proposed approach

  1. Fetch timezone_name from /users/me (IANA name, e.g. Pacific/Auckland), cache alongside the existing current-user info
  2. Add helpers for:
    • todayInTZ(tz): today's date in a specific IANA timezone
    • effectiveDeadline(due_date, due_time, tz): resolves date-only activities (already in user TZ) and timed activities (UTC → local) into a comparable local date / moment
  3. Rewrite the overdue/upcoming filters to use these
  4. For as_user scenarios, use the target user's timezone (from /users entry)

Questions

Handling IANA timezones cleanly in JavaScript is notoriously verbose with stdlib only. Two reasonable implementation paths:

  1. Stdlib only using Intl.DateTimeFormat.formatToParts(), no new deps, but several helper functions and some awkwardness
  2. Add Luxon or similar library (~70KB tree-shakeable, battle-tested) for clean timezone math

Would you prefer to keep the dep footprint minimal, or is a date library acceptable for something this central?

Scope

In scope:

  • pipedrive_my_overdue_activities, pipedrive_my_upcoming_activities
  • Tests covering multiple timezones and both date-only and timed activities

Out of scope:

  • pipedrive_stale_deals / pipedrive_recently_updated (these pass date filters to Pipedrive's API which handles them in UTC, so the current UTC-based daysAgo is roughly correct)

Willing to pick this up once you've confirmed direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions