From ee044e86021a61a343091b1da27bbf567dfb0215 Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 15 May 2024 16:08:43 -0700 Subject: [PATCH] Fix timezone issues --- app/builders/v2/reports/timeseries/count_report_builder.rb | 7 ++++++- spec/controllers/api/v2/accounts/report_controller_spec.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/builders/v2/reports/timeseries/count_report_builder.rb b/app/builders/v2/reports/timeseries/count_report_builder.rb index 45843b20c..03a87a6fa 100644 --- a/app/builders/v2/reports/timeseries/count_report_builder.rb +++ b/app/builders/v2/reports/timeseries/count_report_builder.rb @@ -2,7 +2,12 @@ class V2::Reports::Timeseries::CountReportBuilder < V2::Reports::Timeseries::Bas def timeseries grouped_count.each_with_object([]) do |element, arr| event_date, event_count = element - arr << { value: event_count, timestamp: event_date.to_time.to_i } + + # The `event_date` is in Date format (without time), such as "Wed, 15 May 2024". + # We need a timestamp for the start of the day. However, we can't use `event_date.to_time.to_i` + # because it converts the date to 12:00 AM server timezone. + # The desired output should be 12:00 AM in the specified timezone. + arr << { value: event_count, timestamp: event_date.in_time_zone(timezone).to_i } end end diff --git a/spec/controllers/api/v2/accounts/report_controller_spec.rb b/spec/controllers/api/v2/accounts/report_controller_spec.rb index 27a596243..e10a0ec91 100644 --- a/spec/controllers/api/v2/accounts/report_controller_spec.rb +++ b/spec/controllers/api/v2/accounts/report_controller_spec.rb @@ -18,7 +18,7 @@ RSpec.describe 'Reports API', type: :request do assignee: user, created_at: Time.current.in_time_zone(default_timezone).to_date) end - describe 'GET /api/v2/accounts/:account_id/reports/account' do + describe 'GET /api/v2/accounts/:account_id/reports' do context 'when it is an unauthenticated user' do it 'returns unauthorized' do get "/api/v2/accounts/#{account.id}/reports"