Skip to content

Conversation

@mikeallisonJS
Copy link
Collaborator

@mikeallisonJS mikeallisonJS commented Jan 7, 2026

  • Introduced timezone field in GoogleSheetsSync model to store IANA timezone identifier.
  • Updated appendEventToGoogleSheets function to use stored timezone for date formatting.
  • Modified journeyVisitorExportToGoogleSheet mutation to capture user's timezone for consistent date handling.
  • Added timezone parameter in relevant tests for validation.

Summary by CodeRabbit

  • New Features
    • Google Sheets exports now use your configured timezone for date formatting instead of always defaulting to UTC
    • Dates in exported spreadsheets are now displayed in your timezone preference rather than UTC
    • Your timezone setting is automatically saved with your spreadsheet sync configuration to ensure consistent formatting in all future exports

✏️ Tip: You can customize this high-level summary in your review settings.

- Introduced timezone field in GoogleSheetsSync model to store IANA timezone identifier.
- Updated appendEventToGoogleSheets function to use stored timezone for date formatting.
- Modified journeyVisitorExportToGoogleSheet mutation to capture user's timezone for consistent date handling.
- Added timezone parameter in relevant tests for validation.
@mikeallisonJS mikeallisonJS requested a review from tanflem January 7, 2026 19:55
@mikeallisonJS mikeallisonJS self-assigned this Jan 7, 2026
@linear
Copy link

linear bot commented Jan 7, 2026

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

Walkthrough

The PR adds timezone support to the Google Sheets export feature. It introduces a timezone field to the GoogleSheetsSync database model, creates a database migration, updates the event export utility to format dates using the stored timezone, and modifies the sync creation mutation to persist the user's timezone alongside the sync configuration.

Changes

Cohort / File(s) Summary
Schema & Database
libs/prisma/journeys/db/schema.prisma, libs/prisma/journeys/db/migrations/20260107193142_20260107193140/migration.sql
Added optional timezone String field to GoogleSheetsSync model to store IANA timezone identifiers. Includes corresponding SQL migration to alter the GoogleSheetsSync table.
Event Export Logic
apis/api-journeys-modern/src/schema/event/utils.ts
Enhanced date formatting to use timezone-aware logic via formatDateYmdInTimeZone. Replaces hardcoded UTC references with dynamic syncTimezone derived from sync configuration, applied to header construction and header label resolution.
Google Sheets Sync Mutation
apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.ts
Added timezone: userTimezone field to the syncData payload persisted when creating a new Google Sheets sync configuration.
Sync Mutation Test
apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.spec.ts
Updated test assertion to include timezone: 'UTC' in the expected googleSheetsSync.create payload.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Suggested reviewers

  • tanflem
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add timezone support for Google Sheets sync' clearly and accurately describes the main change: introducing timezone functionality to Google Sheets synchronization. It directly maps to the changeset which adds a timezone field to the GoogleSheetsSync model, updates the mutation to capture user timezone, and modifies the export utility to use timezone-aware date formatting.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mikeallison/nes-1184-add-timezone-to-google-sync-api-no-qa

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Jan 7, 2026

View your CI Pipeline Execution ↗ for commit 6345002

Command Status Duration Result
nx affected --target=subgraph-check --base=a019... ✅ Succeeded 2s View ↗
nx affected --target=extract-translations --bas... ✅ Succeeded <1s View ↗
nx affected --target=lint --base=a0194eaa274c1e... ✅ Succeeded 26s View ↗
nx affected --target=type-check --base=a0194eaa... ✅ Succeeded 19s View ↗
nx run-many --target=codegen --all --parallel=3 ✅ Succeeded 2s View ↗
nx run-many --target=prisma-generate --all --pa... ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-07 19:59:30 UTC

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: 0

🧹 Nitpick comments (2)
apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.spec.ts (1)

245-257: Test correctly verifies default timezone persistence.

The assertion properly expects timezone: 'UTC' when no timezone argument is provided. Consider adding a test case that passes a custom timezone (e.g., 'America/New_York') to verify non-default timezone handling is correctly persisted.

apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.ts (1)

195-207: Consider validating the timezone identifier.

The timezone argument accepts any string with a default of 'UTC'. An invalid IANA timezone (e.g., 'Invalid/Zone') would be persisted and could cause issues when formatDateYmdInTimeZone is called during live sync. The function has a fallback, but storing invalid data is suboptimal.

♻️ Optional: Add validation before using the timezone
+      // Validate timezone is a valid IANA identifier
+      const validateTimezone = (tz: string): boolean => {
+        try {
+          Intl.DateTimeFormat(undefined, { timeZone: tz })
+          return true
+        } catch {
+          return false
+        }
+      }
+
       // Use user's timezone or default to UTC
-      const userTimezone = timezone ?? 'UTC'
+      const userTimezone = timezone && validateTimezone(timezone) ? timezone : 'UTC'
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a0194ea and 6345002.

📒 Files selected for processing (5)
  • apis/api-journeys-modern/src/schema/event/utils.ts
  • apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.spec.ts
  • apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.ts
  • libs/prisma/journeys/db/migrations/20260107193142_20260107193140/migration.sql
  • libs/prisma/journeys/db/schema.prisma
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/base.mdc)

**/*.{ts,tsx,js,jsx}: Use early returns whenever possible to make the code more readable.
Use descriptive variable and function/const names.
Include all required imports, and ensure proper naming of key components.

Files:

  • apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.spec.ts
  • apis/api-journeys-modern/src/schema/event/utils.ts
  • apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/base.mdc)

Define a type if possible.

Files:

  • apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.spec.ts
  • apis/api-journeys-modern/src/schema/event/utils.ts
  • apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.ts
🧠 Learnings (1)
📚 Learning: 2025-11-11T23:22:02.196Z
Learnt from: mikeallisonJS
Repo: JesusFilm/core PR: 8156
File: apis/api-journeys-modern/src/lib/google/googleAuth.ts:0-0
Timestamp: 2025-11-11T23:22:02.196Z
Learning: In apis/api-journeys-modern, use the validated `env` object from `../../env` instead of accessing `process.env` directly for environment variables that are defined in env.ts (e.g., GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, INTEGRATION_ACCESS_KEY_ENCRYPTION_SECRET). This eliminates the need for runtime validation checks since Zod validates them at application startup.

Applied to files:

  • apis/api-journeys-modern/src/schema/event/utils.ts
🧬 Code graph analysis (1)
apis/api-journeys-modern/src/schema/event/utils.ts (1)
apis/api-journeys-modern/src/schema/journeyVisitor/export/date.ts (1)
  • formatDateYmdInTimeZone (4-15)
⏰ 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). (7)
  • GitHub Check: test (22, 2/3)
  • GitHub Check: build (22)
  • GitHub Check: test (22, 3/3)
  • GitHub Check: test (22, 1/3)
  • GitHub Check: affected (22)
  • GitHub Check: lint (22)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
libs/prisma/journeys/db/migrations/20260107193142_20260107193140/migration.sql (1)

1-2: LGTM!

The migration correctly adds a nullable timezone column to store IANA timezone identifiers. The TEXT type is appropriate for this use case.

libs/prisma/journeys/db/schema.prisma (1)

291-291: LGTM!

The optional timezone field with the inline comment explaining the IANA format and example is well-documented. Making it nullable ensures backward compatibility with existing sync records.

apis/api-journeys-modern/src/schema/journeyVisitor/journeyVisitorExportToGoogleSheet.mutation.ts (1)

598-602: Timezone persistence looks correct.

The timezone: userTimezone is properly included in the sync data payload, ensuring the user's timezone preference is stored for consistent date formatting in subsequent live sync operations.

apis/api-journeys-modern/src/schema/event/utils.ts (3)

348-350: LGTM!

The fallback to 'UTC' when sync.timezone is null ensures backward compatibility for existing sync records created before this feature.


418-429: Date formatting with timezone is correctly implemented.

The code safely handles date parsing and formatting with proper guards:

  • Checks for non-empty input
  • Validates the Date object with isNaN check
  • Falls back to the original value if formatting fails

The empty catch block at line 426-428 is acceptable here since preserving the original value is a sensible fallback.


431-436: Row mapping correctly uses formatted date.

The formattedDate variable properly replaces createdAtRaw in the row map, ensuring timezone-aware dates are written to Google Sheets.

@stage-branch-merger
Copy link

I see you added the "on stage" label, I'll get this merged to the stage branch!

@mikeallisonJS mikeallisonJS added this pull request to the merge queue Jan 7, 2026
Merged via the queue into main with commit 7bfbcb0 Jan 7, 2026
26 checks passed
@mikeallisonJS mikeallisonJS deleted the mikeallison/nes-1184-add-timezone-to-google-sync-api-no-qa branch January 7, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants