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

Database and Ruby have inconsistent time zone info #215

Closed
c2ofh opened this issue Mar 15, 2019 · 11 comments
Closed

Database and Ruby have inconsistent time zone info #215

c2ofh opened this issue Mar 15, 2019 · 11 comments

Comments

@c2ofh
Copy link

c2ofh commented Mar 15, 2019

Hi,

i'm confused. Since Rails 5.2 I cannot use Groupdate in rails console.
Groupdate::Error (Database and Ruby have inconsistent time zone info. Database returned 2016-09-01 02:00:00 +0200)

The default Timezone is :utc
config.active_record.default_timezone = :utc

How can I fix this?

@c2ofh c2ofh closed this as completed Mar 15, 2019
@meacuna
Copy link

meacuna commented Apr 9, 2019

I ran into the same issue. Did you manage to solve this @c2ofh ?

@c2ofh
Copy link
Author

c2ofh commented May 11, 2019

@meacuna I was able to solve it, by setting the timezone right before the request.
Time.zone = object.timezone || 'Europe/Berlin'

@ankane
Copy link
Owner

ankane commented May 14, 2019

For future readers, this means Ruby and your database have conflicting time zone info. Based on the time returned, you can determine which is out of date and upgrade accordingly.

@mrgenixus
Copy link

I'm unclear about what you mean by "upgrade" I'm trying to figure out how/when this check is done. Currently, my app works fine, but my tests don't seem to work at all. Could you clarify WHY this is an error, and what it means?

For future readers, this means Ruby and your database have conflicting time zone info. Based on the time returned, you can determine which is out of date and upgrade accordingly.

@ankane
Copy link
Owner

ankane commented Jun 5, 2019

Groupdate does the initial grouping on the database server for performance (uses database time zone), then fills in missing data points in Ruby (uses Ruby time zone). If these are inconsistent, you can get incorrect results. See #209.

To fix, determine which needs updated. You can do this by looking at the time returned in the error.

@mrgenixus
Copy link

I'm confused about this because I don't get this error in development or production, only in my test suite. If I pass a different time_zone to group_by_period, it seems to trigger this error, which, it seems is why I don't get the error.

We seem to be passing the parameter because different users want to see these events localized and grouped based on their time (so users in different timezones would see different graphs). I don't know that this makes sense or is constructive, but it seems to be the way things are done.

I definitely don't have this kind of expertise, where it concerns times and timezones, so I may need it explained like I'm 5. I'm really sorry to be so dense.

Thanks,
-- Ben

Groupdate does the initial grouping on the database server for performance (uses database time zone), then fills in missing data points in Ruby (uses Ruby time zone). If these are inconsistent, you can get incorrect results. See #209.

To fix, determine which needs updated. You can do this by looking at the time returned in the error.

@ankane
Copy link
Owner

ankane commented Jun 5, 2019

The error is specific to the time zone and data retrieved. Not all time zones will have inconsistent data, and not all data retrieved will be affected by inconsistent time zone data. You'll only see the error message if Groupdate detects that the data retrieved *is* affected by this issue.

Unfortunately, I don't have the bandwidth to help with app-specific issues, but maybe you can get help on Stack Overflow.

@mrgenixus
Copy link

Yeah. That's fine, I understand that you have other responsibilities. Thanks for your time.

@inyerade
Copy link

To future readers I solved this problem with @odlp information in #222 (updating tzinfo gem)

@ankane
Copy link
Owner

ankane commented Jan 16, 2022

Just fyi, for Groupdate 6, I've updated the gem to work when time zones are inconsistent, so this error won't appear anymore.

@Fahmiin-Abdullah
Copy link

Your efforts in maintaining this amazing gem is much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants