Skip to content
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

fix: normalizes start date for survey filters #29097

Merged
merged 4 commits into from
Feb 22, 2025

Conversation

lucasheriques
Copy link
Contributor

Problem

similar to how we did it for the end date filter, this will normalize the start date filter to prevent issues where different timezones compute different data

will fix this bug reported internally

Does this work well for both Cloud and self-hosted?

yes

How did you test this code?

smoke tests locally; tested with changing my macbook to different timezones and date remains the same

@lucasheriques lucasheriques requested a review from a team February 22, 2025 04:44
@lucasheriques lucasheriques self-assigned this Feb 22, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR addresses timezone-related inconsistencies in survey filters by normalizing start date handling across different timezones, similar to existing end date normalization.

  • Introduced getSurveyStartDateForQuery function in /frontend/src/scenes/surveys/surveyLogic.tsx to standardize date handling using startOf('day')
  • Updated survey query references to use the new normalization function for consistent date filtering
  • Added timezone-specific test cases in /frontend/src/scenes/surveys/surveyLogic.test.ts to verify consistent behavior across different timezones

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

github-actions bot commented Feb 22, 2025

Size Change: 0 B

Total Size: 9.71 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 9.71 MB

compressed-size-action

@@ -717,7 +723,7 @@ export const surveyLogic = kea<surveyLogicType>([
// Initialize date range based on survey dates when survey is loaded
if ('created_at' in values.survey) {
const dateRange = {
date_from: dayjs(values.survey.created_at).startOf('day').format(DATE_FORMAT),
date_from: getSurveyStartDateForQuery(values.survey),
Copy link
Member

Choose a reason for hiding this comment

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

so here it was using created_at only, but the new function uses start and created, with a preference for start, I believe this would be a bug?

Copy link
Member

Choose a reason for hiding this comment

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

the code even check for the existence of 'created_at'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all the other dates have always used the start_date as the default date, this was the only one that was using only created_at. so it's more about doing the same behavior to this date range as well

Copy link
Member

Choose a reason for hiding this comment

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

then i think you should remove the if ('created_at' in values.survey) { condition, which wouldn't make sense anymore?

Copy link
Member

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

2 comments to resolve otherwise LGTM

@lucasheriques lucasheriques enabled auto-merge (squash) February 22, 2025 18:38
@lucasheriques lucasheriques merged commit 13a1f6b into master Feb 22, 2025
98 checks passed
@lucasheriques lucasheriques deleted the fix/normalizes-start-date-for-survey-filters branch February 22, 2025 19:04
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