Skip to content

fix: timezone parsing issues for calendars #21665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

curiousgeorgios
Copy link
Contributor

@curiousgeorgios curiousgeorgios commented Jun 1, 2025

What does this PR do?

  • After reviewing current issues, there are a number of issues raised in relation to calendar discrepancies, which this PR is likely to solve.
  • I couldn't find a specific issue in Linear calling this timezone bug out. I noticed and troubleshot this bug myself as I noticed a discrepancy between the timezone in my ICS calendar and what Cal was showing.

Visual Demo (For contributors especially)

Below is a troubleshooting event that I setup on my ICS calendar provider

BEGIN:VEVENT
UID:`REDACTED`
DTSTAMP:20250601T105202Z
SUMMARY:11-12 on 4 June - +2 Timezone
DTSTART;TZID=Europe/Brussels:20250604T110000
DTEND;TZID=Europe/Brussels:20250604T120000
SEQUENCE:0
STATUS:CONFIRMED
END:VEVENT

And this event is showing as 0300 to 0400 (in the same timezone settings in cal)
image

Video Demo (if applicable):

Not applicable

Image Demo (if applicable):

See screenshots above

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox. N/A
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist


Summary by cubic

Fixed calendar timezone parsing to correctly handle TZID values from ICS files, preventing event time discrepancies.

@curiousgeorgios curiousgeorgios requested a review from a team as a code owner June 1, 2025 12:03
Copy link

vercel bot commented Jun 1, 2025

@curiousgeorgios is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jun 1, 2025
@graphite-app graphite-app bot requested a review from a team June 1, 2025 12:03
Copy link
Contributor

github-actions bot commented Jun 1, 2025

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "fix timezone parsing issues for calendars". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@dosubot dosubot bot added the 🐛 bug Something isn't working label Jun 1, 2025
@curiousgeorgios curiousgeorgios changed the title fix timezone parsing issues for calendars fix: timezone parsing issues for calendars Jun 1, 2025
Copy link

graphite-app bot commented Jun 1, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (06/01/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (06/01/25)

1 label was added to this PR based on Keith Williams's automation.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

cubic found 2 issues across 2 files. Review them in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

// Fix timezone extraction - get TZID from DTSTART property parameters
const dtstartProperty = vevent.getFirstProperty("dtstart");
const tzidFromDtstart = dtstartProperty?.getParameter("tzid");

Copy link
Contributor

Choose a reason for hiding this comment

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

Line contains only whitespace which violates project formatting guidelines and adds unnecessary diff noise.

Suggested change

Copy link
Contributor

@Devanshusharma2005 Devanshusharma2005 left a comment

Choose a reason for hiding this comment

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

Address the cubic suggestions.

@Devanshusharma2005 Devanshusharma2005 marked this pull request as draft June 11, 2025 13:29
…n methods


accepting the cubic-dev-ai as implement backward compatibility with different event ICS event types

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@curiousgeorgios
Copy link
Contributor Author

Address the cubic suggestions.

thanks @Devanshusharma2005 - updated.

@Devanshusharma2005
Copy link
Contributor

@curiousgeorgios getting typecheck issues.

Copy link
Contributor

github-actions bot commented Jul 8, 2025

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Jul 8, 2025
@Devanshusharma2005
Copy link
Contributor

marking this pr as closed due to inactivity. Feel free to ping me up if you want to continue to work on this.

@anikdhabal anikdhabal marked this pull request as ready for review July 11, 2025 15:20
anikdhabal
anikdhabal previously approved these changes Jul 11, 2025
Copy link
Contributor

@anikdhabal anikdhabal left a comment

Choose a reason for hiding this comment

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

Looking good

@anikdhabal anikdhabal removed the Stale label Jul 11, 2025
@dosubot dosubot bot added the calendar-apps area: calendar, google calendar, outlook, lark, microsoft 365, apple calendar label Jul 11, 2025
@curiousgeorgios
Copy link
Contributor Author

Looking good

thank you brother

@anikdhabal
Copy link
Contributor

@curiousgeorgios could you pls also attach the after image

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

cubic reviewed 2 files and found no issues. Review PR in cubic.dev.

@anikdhabal anikdhabal enabled auto-merge (squash) July 11, 2025 15:26
@curiousgeorgios
Copy link
Contributor Author

@curiousgeorgios could you pls also attach the after image

yep will do that 👌

@kart1ka
Copy link
Contributor

kart1ka commented Jul 15, 2025

@curiousgeorgios A type check seems to be failing. Can you fix that?

@anikdhabal anikdhabal added the Medium priority Created by Linear-GitHub Sync label Jul 16, 2025
- Fix VTIMEZONE selection to find matching timezone instead of using first one
- Improve TZID parameter extraction from DTSTART property using jCal array
- Fix precedence: DTSTART TZID > standalone TZID > UTC > fallback
- Resolves issue where Europe/Brussels events showed wrong times in Europe/Paris
auto-merge was automatically disabled July 16, 2025 17:50

Head branch was pushed to by a user without write access

Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

The changes focus on improving timezone handling and event time conversion logic within calendar service classes. The extraction of the timezone identifier (TZID) now gives precedence to the TZID parameter from the DTSTART property, accessed via its internal structure, rather than relying on a standalone TZID property or defaulting to UTC. When selecting the relevant VTIMEZONE component from the calendar data, the updated logic matches the component's TZID with the event's TZID, falling back to the first available VTIMEZONE if no match is found. Additionally, event start and end times are converted to ISO strings once and stored in variables before being added to the results, reducing redundant conversions. No public or exported entity signatures are changed.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/app-store/ics-feedcalendar/lib/CalendarService.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-playwright".

(The package "eslint-plugin-playwright" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-playwright@latest --save-dev

The plugin "eslint-plugin-playwright" was referenced from the config file in ".eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/lib/CalendarService.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-playwright".

(The package "eslint-plugin-playwright" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-playwright@latest --save-dev

The plugin "eslint-plugin-playwright" was referenced from the config file in ".eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/app-store/ics-feedcalendar/lib/CalendarService.ts (1)

162-165: Apply the same type safety improvements as in BaseCalendarService.

This code has the same jCal array access pattern that could benefit from error handling.

-        // Fix timezone extraction - get TZID from DTSTART property parameters
-        const dtstartProperty = vevent.getFirstProperty("dtstart");
-        // In ical.js, parameters are accessible through the property's jCal array structure: [name, params, type, value]
-        const tzidFromDtstart = dtstartProperty ? (dtstartProperty as any).jCal[1].tzid : undefined;
+        // Fix timezone extraction - get TZID from DTSTART property parameters
+        const dtstartProperty = vevent.getFirstProperty("dtstart");
+        // In ical.js, parameters are accessible through the property's jCal array structure: [name, params, type, value]
+        let tzidFromDtstart: string | undefined;
+        try {
+          tzidFromDtstart = dtstartProperty && (dtstartProperty as any).jCal?.[1]?.tzid;
+        } catch (e) {
+          console.error("Error extracting TZID from DTSTART property:", e);
+          tzidFromDtstart = undefined;
+        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2bbbf3 and ae112e6.

📒 Files selected for processing (2)
  • packages/app-store/ics-feedcalendar/lib/CalendarService.ts (3 hunks)
  • packages/lib/CalendarService.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
packages/app-store/ics-feedcalendar/lib/CalendarService.ts (1)
Learnt from: hariombalhara
PR: calcom/cal.com#22547
File: packages/embeds/embed-core/src/lib/eventHandlers/scrollByDistanceEventHandler.ts:11-14
Timestamp: 2025-07-16T11:46:28.738Z
Learning: In Cal.com's embed system, internal events like "__scrollByDistance" are fired by Cal.com's own code, so runtime validation of event data structure is unnecessary since TypeScript type system guarantees type safety for internal events.
packages/lib/CalendarService.ts (1)
Learnt from: hariombalhara
PR: calcom/cal.com#22547
File: packages/embeds/embed-core/src/lib/eventHandlers/scrollByDistanceEventHandler.ts:11-14
Timestamp: 2025-07-16T11:46:28.738Z
Learning: In Cal.com's embed system, internal events like "__scrollByDistance" are fired by Cal.com's own code, so runtime validation of event data structure is unnecessary since TypeScript type system guarantees type safety for internal events.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: apply-labels-from-issue
  • GitHub Check: Security Check
  • GitHub Check: Security Check
🔇 Additional comments (4)
packages/lib/CalendarService.ts (3)

405-407: LGTM! Correct timezone precedence implementation.

The updated TZID precedence logic correctly prioritizes the DTSTART parameter while maintaining proper fallbacks, addressing the timezone parsing issues mentioned in the PR objectives.


436-447: Excellent improvement to VTIMEZONE selection logic.

The code now correctly searches for a VTIMEZONE component that matches the event's TZID instead of always using the first one. This ensures proper timezone handling when multiple timezones are defined in the calendar.


519-524: Good refactoring for readability and performance.

Caching the ISO string conversions in variables improves code readability and avoids redundant conversions.

packages/app-store/ics-feedcalendar/lib/CalendarService.ts (1)

203-289: Excellent consistency with BaseCalendarService implementation.

The timezone handling improvements are consistently implemented across both calendar service classes, ensuring uniform behavior for timezone parsing throughout the application.

Comment on lines +396 to +399
// Fix timezone extraction - get TZID from DTSTART property parameters
const dtstartProperty = vevent.getFirstProperty("dtstart");
// In ical.js, parameters are accessible through the property's jCal array structure: [name, params, type, value]
const tzidFromDtstart = dtstartProperty ? (dtstartProperty as any).jCal[1].tzid : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add type safety and error handling for jCal array access.

The code correctly extracts TZID from DTSTART parameters, but accessing the internal jCal structure without proper type checking could lead to runtime errors if the array structure is unexpected.

Consider adding error handling:

-        // Fix timezone extraction - get TZID from DTSTART property parameters
-        const dtstartProperty = vevent.getFirstProperty("dtstart");
-        // In ical.js, parameters are accessible through the property's jCal array structure: [name, params, type, value]
-        const tzidFromDtstart = dtstartProperty ? (dtstartProperty as any).jCal[1].tzid : undefined;
+        // Fix timezone extraction - get TZID from DTSTART property parameters
+        const dtstartProperty = vevent.getFirstProperty("dtstart");
+        // In ical.js, parameters are accessible through the property's jCal array structure: [name, params, type, value]
+        let tzidFromDtstart: string | undefined;
+        try {
+          tzidFromDtstart = dtstartProperty && (dtstartProperty as any).jCal?.[1]?.tzid;
+        } catch (e) {
+          console.error("Error extracting TZID from DTSTART property:", e);
+          tzidFromDtstart = undefined;
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Fix timezone extraction - get TZID from DTSTART property parameters
const dtstartProperty = vevent.getFirstProperty("dtstart");
// In ical.js, parameters are accessible through the property's jCal array structure: [name, params, type, value]
const tzidFromDtstart = dtstartProperty ? (dtstartProperty as any).jCal[1].tzid : undefined;
// Fix timezone extraction - get TZID from DTSTART property parameters
const dtstartProperty = vevent.getFirstProperty("dtstart");
// In ical.js, parameters are accessible through the property's jCal array structure: [name, params, type, value]
let tzidFromDtstart: string | undefined;
try {
tzidFromDtstart = dtstartProperty && (dtstartProperty as any).jCal?.[1]?.tzid;
} catch (e) {
console.error("Error extracting TZID from DTSTART property:", e);
tzidFromDtstart = undefined;
}
🤖 Prompt for AI Agents
In packages/lib/CalendarService.ts around lines 396 to 399, the code accesses
the internal jCal array of the dtstartProperty without type safety or checks,
which risks runtime errors if the structure is not as expected. To fix this, add
type checks to ensure dtstartProperty.jCal exists, is an array, and has the
expected elements before accessing the tzid property. Also, include error
handling or fallback logic if the tzid is not found or the structure is invalid
to prevent crashes.

@curiousgeorgios
Copy link
Contributor Author

curiousgeorgios commented Jul 16, 2025

hey guys turns should be all working and good to go now:

have tested as per the commit and here is the after pics and timezones lining up perfectly. Summary of the events:


Timeline: ICS Feed Timezone Handling Bug

Issue Discovery

  • Problem: ICS calendar events displaying with 8-hour timezone offset errors
  • Example: Event DTSTART;TZID=Europe/Brussels:20250604T110000 showing as 03:00-04:00 in Europe/Paris instead of correct 11:00-12:00
  • Impact: All ICS feed events showing incorrect times, breaking calendar functionality

Root Cause Investigation

Bug #1: Incorrect VTIMEZONE Selection

// BROKEN: Always used first VTIMEZONE regardless of event's actual timezone
const vtimezone = vcalendar.getFirstSubcomponent("vtimezone");
  • ICS files contain multiple VTIMEZONE definitions (Australia/Sydney, Europe/Brussels, etc.)
  • Code blindly selected first VTIMEZONE (Australia/Sydney) for ALL events
  • Brussels events incorrectly processed with Sydney timezone rules

Bug #2: Failed TZID Parameter Extraction

// BROKEN: Attempted to extract timezone from non-existent property
const timezone = dtstart ? dtstart["timezone"] : undefined;
  • Failed to extract TZID=Europe/Brussels from DTSTART property parameters
  • Incorrect fallback logic precedence

Solution Implementation

Fix #1: Smart VTIMEZONE Matching

// FIXED: Find VTIMEZONE that matches event's TZID
let vtimezone = null;
if (tzid) {
  const allVtimezones = vcalendar.getAllSubcomponents("vtimezone");
  vtimezone = allVtimezones.find((vtz) => vtz.getFirstPropertyValue("tzid") === tzid);
}
if (!vtimezone) {
  vtimezone = vcalendar.getFirstSubcomponent("vtimezone"); // Fallback
}

Fix #2: Correct TZID Parameter Extraction

// FIXED: Use ical.js jCal array structure for parameter access
const dtstartProperty = vevent.getFirstProperty("dtstart");
const tzidFromDtstart = dtstartProperty ? (dtstartProperty as any).jCal[1].tzid : undefined;

Fix #3: Proper Fallback Priority

// FIXED: Complete fallback chain with correct precedence
const tzid = tzidFromDtstart || vevent?.getFirstPropertyValue("tzid") || (isUTC ? "UTC" : timezone);

Files Modified

  • packages/app-store/ics-feedcalendar/lib/CalendarService.ts
  • packages/lib/CalendarService.ts

Testing

  • Before: Europe/Brussels 11:00-12:00 event displayed as 03:00-04:00 in Europe/Paris ❌
  • After: Europe/Brussels 11:00-12:00 event displays as 11:00-12:00 in Europe/Paris ✅

Result

  • Eliminated 8-hour timezone offset errors
  • ICS events now display with correct timezone conversion
  • Maintained backward compatibility with all ICS feed formats
  • Proper fallback handling for edge cases (UTC events, standalone TZID properties)

This fix resolves timezone handling issues for ICS calendar feeds and ensures events display at the correct local times.

Screenshots after the fix:

Screenshot 2025-07-16 at 6 42 07 pm Screenshot 2025-07-16 at 6 41 51 pm

@curiousgeorgios
Copy link
Contributor Author

@anikdhabal grateful for your review to try and get this merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working calendar-apps area: calendar, google calendar, outlook, lark, microsoft 365, apple calendar community Created by Linear-GitHub Sync Medium priority Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants