Fix timezone issues

This commit is contained in:
Pranav
2024-05-15 20:42:55 -07:00
parent 3b7421221c
commit ee044e8602
2 changed files with 7 additions and 2 deletions
@@ -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
@@ -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"