Skip to content

fix(login): send client timezone for analytics requests#27

Closed
Suyash-ka-github wants to merge 3 commits intobrowseping:mainfrom
Suyash-ka-github:fix/login-send-timezone
Closed

fix(login): send client timezone for analytics requests#27
Suyash-ka-github wants to merge 3 commits intobrowseping:mainfrom
Suyash-ka-github:fix/login-send-timezone

Conversation

@Suyash-ka-github
Copy link

@Suyash-ka-github Suyash-ka-github commented Jan 27, 2026

Description

This PR updates the frontend to send the user’s local timezone with analytics API requests so that analytics data (especially hourly presence) is calculated correctly on the backend.

This change is the frontend counterpart to the server-side fix introduced in PR browseping/server#20 (fix(analytics): correct hourly presence using user timezone).


Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Related Issue


Changes Made

  • Added user timezone using Intl.DateTimeFormat().resolvedOptions().timeZone
  • Updated fetchHourlyPresence API call to include timezone as a query parameter
  • Ensured changes are limited to analytics-related requests only
  • No impact on authentication or other API calls

Testing Done

  • Logged in and triggered analytics requests from the frontend
  • Verified timezone is correctly sent in the request query
  • Confirmed backend returns different hourly data for different timezones (Asia/Kolkata vs Asia/Tokyo)
  • Verified no regressions in existing functionality

Checklist

  • I have read and followed all guidelines in CONTRIBUTING.md
  • I have used the correct branch naming convention (fix/login-send-timezone)
  • My commits follow Conventional Commits format (fix:)
  • I have performed a self-review and tested my changes thoroughly
  • CRITICAL: I confirm ONLY my intended changes are included
  • No documentation update required

Screenshots (if applicable)

Not applicable — no UI changes.


Additional Notes

This PR complements the backend analytics timezone fix by ensuring the frontend sends the correct user timezone without introducing additional logic on the client side.

@Suyash-ka-github
Copy link
Author

Related to: browseping/server#20

@Suyash-ka-github
Copy link
Author

Hello @akash-kumar-dev this is the frontend changes Made for the issue 20 from server

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds client timezone information to analytics API requests to ensure accurate hourly presence and tab usage calculations on the backend. The changes send the user's timezone (obtained via JavaScript's Intl API) as a query parameter to analytics endpoints.

Changes:

  • Added timezone detection using Intl.DateTimeFormat().resolvedOptions().timeZone
  • Updated fetchWeeklyTabUsage to include timezone query parameter
  • Updated fetchHourlyPresence to include timezone query parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

headers: { Authorization: `Bearer ${token}` }
}
);
return res.json();
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

Missing await keyword before res.json(). While this doesn't break functionality (the promise is still returned correctly), it's inconsistent with other similar functions in this file (see lines 135, 153, 160, 168, 176, 211, 219, 261) that use return await res.json(). For consistency and better error handling within this function's scope, add the await keyword.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +191 to +192
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;

Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The timezone retrieval using Intl.DateTimeFormat().resolvedOptions().timeZone lacks error handling. If this API fails or returns undefined in some browsers or environments, the function will silently pass an undefined or malformed timezone parameter. Consider adding a try-catch block with a fallback timezone (e.g., 'UTC') or validation to ensure the timezone is valid before using it.

Suggested change
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
let timezone = 'UTC';
try {
const options = typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat === 'function'
? Intl.DateTimeFormat().resolvedOptions()
: null;
if (options && typeof options.timeZone === 'string' && options.timeZone.trim() !== '') {
timezone = options.timeZone;
}
} catch {
// Fallback to default 'UTC' timezone if retrieval fails
}

Copilot uses AI. Check for mistakes.
const res = await fetch(`${BACKEND_URL}/api/analytics/presence/hourly?days=${days}`, {
headers: { Authorization: `Bearer ${token}` }
});
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The timezone retrieval using Intl.DateTimeFormat().resolvedOptions().timeZone lacks error handling. If this API fails or returns undefined in some browsers or environments, the function will silently pass an undefined or malformed timezone parameter. Consider adding a try-catch block with a fallback timezone (e.g., 'UTC') or validation to ensure the timezone is valid before using it.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Suyash-ka-github Suyash-ka-github closed this by deleting the head repository Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments