Skip to content

fix(google): refuse impossible calendar dates and clock times in event times - #51166

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/calendar-event-impossible-date
Nov 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/calendar-event-impossible-date

Conversation

@Pr1p

@Pr1p Pr1p commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Asking for a meeting on February 30 quietly put it on March 2, because JavaScript's date parser rolls days a month doesn't have into the next month. Now the calendar commands say the date isn't a real one, the same way automations --by already does. A time like 25:00 now gets a clear message instead of an internal error.

What Changed

  • parseEventTime (src/main/google/google-event-time.ts) runs hasImpossibleLeadingDate on the trimmed value before anything else and throws a GoogleToolError (--start takes a real calendar date; 2027-02-30 is not one.). For a bare local time it also reads the clock back through Date.parse, so 25:00 / 10:60 get a usage error instead of the RangeError that Intl raised inside zonedInstant. 24:00 is still accepted.
  • windowBound (src/main/google/google-time-zone.ts) returns null for an impossible day, so --from / --to answer with their existing usage text.
  • calendar-date.ts moves unchanged from src/cli/arguments to src/shared/validation so the main process can import it; the three CLI importers (automation-once-flag, linear-request-builders, slack-action-args) take the new path.

Before / after (Asia/Shanghai):

input before after
--start 2027-02-30T10:00 event at 2027-03-02T02:00:00Z --start takes a real calendar date; 2027-02-30 is not one.
--start 2027-02-30 (all-day) Google is sent start.date: "2027-02-30" same message
list --from 2027-02-30 window starts 2027-02-30T00:00:00+08:00 existing --from usage error
--start 2027-03-05T25:00 RangeError: Invalid time value --start takes a real clock time; 25:00 is not one.

This covers orca calendar create|update --start/--end (CLI and agent tool) and orca calendar list|suggest-time --from/--to, since they share these parsers.

Why

#50988 added hasImpossibleLeadingDate for automations --by, but the calendar parsers never used it. Reusing it keeps one definition of "a day the calendar has". Moving it to src/shared (rather than listing a src/cli file in config/tsconfig.node.json) avoids making the Electron main process depend on a CLI argument module. The clock check uses Date.parse like the offset branch next to it, which keeps 24:00 valid.

Linked Issue

Fixes #51161

Visual Proof

N/A: no UI change. The difference is only the event time sent to Google or the error text a CLI/agent tool call returns, shown in the table above and asserted in the new test.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • New src/main/google/google-calendar-impossible-date.test.ts calls the real parseEventTime and windowBound with no mocks: 2027-02-30, 2027-02-30T10:00, 2026-02-29 09:00, 2027-04-31T10:00Z throw GoogleToolError while the leap day 2028-02-29T10:00 resolves; 10:60 and 25:00 throw GoogleToolError while 24:00 resolves; windowBound returns null for 2027-02-30 and the zone midnight for 2027-02-28. With the fix reverted all three fail.

  • Targeted vitest on the rebased commit (fresh main): src/main/google/google-calendar-impossible-date.test.ts plus src/cli/automations, src/cli/linear, src/cli/slack suites: 10 files, 62 tests pass.

  • CI static gates on the touched files pass: anti-slop oxlint, code-quality oxlint, ast-grep, oxfmt, and the changed-code quality gate.

  • Platform: macOS (pure string/date logic, no platform-specific code).

Performance

None, because this only runs once per parsed --start/--end/--from/--to flag on a calendar command. Measured the added helper at about 0.24-0.68 µs per call (vs 0.14-0.34 µs for the existing Date.parse), and 13 ns on a 100 KB non-date string because the anchored regex fails on the first character. No rendering, polling, IPC fan-out, I/O or subprocess work is involved.

Risk

Level: Low

Only inputs naming a day the calendar doesn't have, or a clock time that doesn't exist, change behavior: they used to produce a different day or an internal error and now produce a usage error. The helper move is a pure rename with no content change. Back out with a plain revert.

Review

Original fix by @Pr1p in #51166; squashed onto current main with authorship preserved.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Not platform-specific. Mixed-version remote compat is unaffected: no protocol or payload shape changes, only stricter local validation of flag strings.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Google calendar event-time parsing now rejects impossible leading dates and invalid clock values in local date-time inputs. Window-bound parsing returns null for impossible leading dates. Tests cover invalid inputs and valid leap-day, 24:00, and Shanghai-midnight cases. Three CLI modules now import the date validator from the shared validation module.

Severity of issue fixed: Medium

Merge Risk: Low · up to 0bfca

Calendar commands now reject impossible dates, but local times with impossible seconds such as :99 can still be accepted. This is a small gap that can be fixed before or after merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Issue #51161 requires calendar commands to reject impossible dates and invalid clock times with a usage error. At the reviewed head, parseEventTime (src/main/google/google-event-time.ts) calls `ha…
Out of Scope Changes check Passed All changes support the objective in #51161. google-event-time.ts and google-time-zone.ts hold the validation. calendar-date.ts moves from src/cli/arguments to src/shared/validation with unc…
Title check Passed The title names the main change: calendar event time parsing now refuses impossible calendar dates and clock times. It matches the changeset (google-event-time.ts, google-time-zone.ts, and the new val…
Description check Passed The description follows the template and fills in every required section. It has ELI5, What Changed, Why, a linked issue (Fixes #51161), a Visual Proof N/A with reason, Testing, Performance, Risk with…
Full details: Linked Issues check

Explanation

Issue #51161 requires calendar commands to reject impossible dates and invalid clock times with a usage error. At the reviewed head, parseEventTime (src/main/google/google-event-time.ts) calls hasImpossibleLeadingDate before any other branch. It throws GoogleToolError for 2027-02-30T10:00 and for all-day 2027-02-30. The DAY branch now runs after that check, so an invalid all-day date no longer reaches Google as start.date. The local branch reads the clock back through Date.parse(${date}T${time}:00Z) and throws GoogleToolError for 25:00 and 10:60, which prevents the RangeError from Intl in zonedInstant. 24:00 still passes this check. The helper body in src/shared/validation/calendar-date.ts was read at head: it compares the Date.UTC read-back to year, month, and day, so Feb 30 and Apr 31 are refused and Feb 29 in a leap year is accepted. Per the PR summary, windowBound (src/main/google/google-time-zone.ts) returns null for an impossible leading date. I did not re-read the windowBound diff in this pass; that part rests on the raw summary and the previous assessment. The new test file covers these cases without mocks.

Full details: Out of Scope Changes check

Explanation

All changes support the objective in #51161. google-event-time.ts and google-time-zone.ts hold the validation. calendar-date.ts moves from src/cli/arguments to src/shared/validation with unchanged content. The move is needed because the main-process tsconfig cannot import src/cli files (TS6307), and the main process now imports the helper. The three CLI importers (automation-once-flag, linear-request-builders, slack-action-args) change only their import path. The new test file exercises the changed parsers. No unrelated behavior change appears in the diffs read or in the summary.

Full details: Title check

Explanation

The title names the main change: calendar event time parsing now refuses impossible calendar dates and clock times. It matches the changeset (google-event-time.ts, google-time-zone.ts, and the new validation). It uses the conventional commit form and fits in one sentence.

Full details: Description check

Explanation

The description follows the template and fills in every required section. It has ELI5, What Changed, Why, a linked issue (Fixes #51161), a Visual Proof N/A with reason, Testing, Performance, Risk with level Low, and the checklists. It explains the mechanism, the before/after behavior, and the rollback path. The AI Disclosure section is blank, but the template says to skip it for internal contributors, so this is acceptable.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3592feb-e077-41f0-84e4-269654a868ea
Commits

Reviewing files that changed from the base of the PR and between 65542fc and 0bfca11.

Files selected for processing: 3

  • src/main/google/google-event-time.ts
  • src/main/google/google-time-zone.ts
  • src/shared/validation/calendar-date.ts
Files with no reviewable changes: 1

  • src/shared/validation/calendar-date.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7020373c-a40a-44a8-9e4e-6e5d3143b95a
Commits

Reviewing files that changed from the base of the PR and between d4ed6c2 and 65542fc.

Files selected for processing: 7

  • src/cli/automations/automation-once-flag.ts
  • src/cli/linear/linear-request-builders.ts
  • src/cli/slack/slack-action-args.ts
  • src/main/google/google-calendar-impossible-date.test.ts
  • src/main/google/google-event-time.ts
  • src/main/google/google-time-zone.ts
  • src/shared/validation/calendar-date.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment thread src/main/google/google-event-time.ts Outdated
}
const local = LOCAL.exec(trimmed)
// Why: the clock is checked here because a local 25:00 reaches Intl, which throws a RangeError.
if (local?.[2] && Number.isNaN(Date.parse(`${local[1]}T${local[2]}:00Z`))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Validate optional seconds before accepting a local clock.

For 2027-03-05T10:00:99, LOCAL matches but captures only 10:00. This check validates 10:00:00, and zonedInstant returns a successful result. The impossible seconds never reach validation.

Validate the complete matched clock, including optional seconds. Keep valid 10:00 and 24:00 inputs accepted.

Based on learnings, clock-range validation must cover all accepted clock fields.

Source: Learnings

Calendar --start/--end and --from/--to passed dates like 2027-02-30
through Date.parse, which rolled them into the next month (or sent the
raw invalid day to Google). They now reuse hasImpossibleLeadingDate and
answer with a usage error. A local clock like 25:00 or 10:60 also gets
a usage error instead of an Intl RangeError; 24:00 is still accepted.

The helper moves from src/cli/arguments to src/shared/validation so the
main process can import it; the three CLI importers take the new path.

Fixes stablyai#51161

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/calendar-event-impossible-date branch from 65542fc to 0bfca11 Compare November 27, 2026 22:47
@nwparker nwparker changed the title fix(google): refuse impossible calendar dates in event times fix(google): refuse impossible calendar dates and clock times in event times Nov 27, 2026
@nwparker
nwparker merged commit f9d30a6 into stablyai:main Nov 27, 2026
62 checks passed
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.

[Bug]: Calendar commands put an impossible date like Feb 30 on another day

2 participants