Question: Rails TimeZone issue - Group query

Question

Rails TimeZone issue - Group query

Answers 0
Added at 2017-01-04 11:01
Tags
Question

I have my server in NYC and the data in PostgreSQL is stored in UTC but all my data on the presentational layer is to be shown in IST

I have the following settings done

config/application.rb

config.time_zone = 'Asia/Kolkata'
config.active_record.default_timezone = :local # Or :utc

When doing a query i am doing the following

Influencer.where(created_at: DateTime.now.in_time_zone-(days-1).days..DateTime.now.in_time_zone).group("created_at::date").count

but because of the grouping i am still not able to get the right data segmented by the required timezone.

What is the Problem?

On Jan 3rd - X signups IST On Jan 4th - Y signups IST

but the Y - Z which happened in the timezone difference is being added to X when i run a above query.

Any pointers on how to handle this?

Answers to

Rails TimeZone issue - Group query

Source Show
◀ Wstecz