Skip to content

fix(calendar): use local day boundaries for agenda date filters#369

Open
sonwr wants to merge 2 commits intogoogleworkspace:mainfrom
sonwr:fix/agenda-local-day-boundaries
Open

fix(calendar): use local day boundaries for agenda date filters#369
sonwr wants to merge 2 commits intogoogleworkspace:mainfrom
sonwr:fix/agenda-local-day-boundaries

Conversation

@sonwr
Copy link

@sonwr sonwr commented Mar 10, 2026

This fixes calendar +agenda date filters so they respect local day boundaries instead of using UTC/current-time windows.

Fixes #259

What changed:

  • --today now queries from local midnight to the next local midnight
  • --tomorrow now queries the next local calendar day
  • --week now starts at local midnight today
  • --days N now starts at local midnight today and spans N local calendar days
  • default +agenda behavior without date flags remains unchanged (now to now + 24h)

Why:
The previous implementation used:

  • now..now+86400 for --today / --days
  • UTC epoch day boundaries for --tomorrow

That produced incorrect results in non-UTC timezones, especially later in the day, where --today could include tomorrow’s events.

Tests added:

  • test_compute_agenda_range_today_uses_local_midnight_boundaries
  • test_compute_agenda_range_tomorrow_uses_next_local_day
  • test_compute_agenda_range_days_starts_at_local_midnight

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

⚠️ No Changeset found

Latest commit: 573c978

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Mar 10, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the calendar agenda date filtering, where previous implementations led to incorrect results in non-UTC timezones. By refactoring the date range computation to use local day boundaries and the chrono crate, the agenda commands now accurately reflect local time, preventing issues like --today inadvertently including tomorrow's events.

Highlights

  • Agenda Date Filtering: The calendar +agenda date filters now correctly respect local day boundaries, moving away from UTC/current-time windows.
  • --today flag: The --today flag now queries events from local midnight to the next local midnight.
  • --tomorrow flag: The --tomorrow flag now queries events for the entire next local calendar day.
  • --week flag: The --week flag now correctly starts its query at local midnight today.
  • --days N flag: The --days N flag now starts at local midnight today and spans N local calendar days.
  • Default +agenda behavior: The default +agenda behavior, without specific date flags, remains unchanged, querying from now to now + 24h.
Changelog
  • src/helpers/calendar.rs
    • Refactored the time range determination logic in handle_agenda to delegate to a new compute_agenda_range function.
    • Introduced local_date_range function to calculate timezone-aware start and end times for a given date and duration.
    • Implemented compute_agenda_range to centralize the logic for --today, --tomorrow, --week, and --days N flags, ensuring local midnight boundaries are used.
    • Added a new test helper function make_matches_agenda for creating ArgMatches specific to agenda tests.
    • Included three new unit tests: test_compute_agenda_range_today_uses_local_midnight_boundaries, test_compute_agenda_range_tomorrow_uses_next_local_day, and test_compute_agenda_range_days_starts_at_local_midnight to validate the new date range calculations.
Activity
  • No specific activity (comments, reviews, progress) was provided in the context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly refactors the agenda date filtering logic to respect local timezones, fixing a bug where events could be shown on the wrong day. The new implementation is moved into separate, testable functions, and new unit tests have been added to verify the behavior with different timezone offsets. The changes are a significant improvement.

My review includes one suggestion to handle an edge case where a user might provide --days 0, which would currently lead to an API error. Adding a validation check for this would improve the user experience.

.get_one::<String>("days")
.and_then(|s| s.parse::<u64>().ok())
{
return local_date_range(&now.timezone(), local_date, days);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The code doesn't handle the case where a user provides --days 0. This will result in time_min and time_max being identical, which is invalid for the Google Calendar API (it requires timeMin to be smaller than timeMax). This will lead to an API error. It would be better to validate this input and return a user-friendly error.

A check should be added to ensure the number of days is positive.

        if days == 0 {
            return Err(GwsError::Validation("Number of days for agenda must be a positive integer.".to_string()));
        }
        return local_date_range(&now.timezone(), local_date, days);

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

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agenda --today uses UTC for day boundaries, wrong results in non-UTC timezones

2 participants