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

Fixes #13557 - Rubocop enforce specifying a timezone #3156

Closed
wants to merge 1 commit into from

Conversation

dLobatog
Copy link
Member

@dLobatog dLobatog commented Feb 4, 2016

Rubocop can enforce what timezone to store in the database ,
so we can ensure everything is stored using UTC and we don't
miss these things in code reviews. When objects are displayed,
they must use the time provided by set_timezone in the
controller.

This is particularly relevant for Trends, Puppet graphs, etc... to
ensure they are stored always properly

theforeman/theforeman.org#535

dLobatog added a commit to dLobatog/theforeman.org that referenced this pull request Feb 4, 2016
Basically making sure the content of
theforeman/foreman#3156

remains a guideline and new developers or plugin developers know how to
store time.
@@ -27,7 +27,7 @@ def trend_title(trend)
end
end

def chart_data(trend, from = Setting.max_trend, to = Time.zone.now)
def chart_data(trend, from = Setting.max_trend, to = Time.now.utc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you have to make this change? I ask because Time.zone should have a timezone and according to the Rails documentation, it may not be UTC.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I think this is fine since it's a default value.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not actually used in the trend counter retrieval, but if it was, then UTC would be correct.

@dLobatog dLobatog force-pushed the timezone branch 2 times, most recently from e51e69d to 191e062 Compare February 4, 2016 19:49
@shlomizadok
Copy link
Member

This seems to ignore user's timezone (which defaults to utc if not set). I'd think we may want to use Time.zone.now instead of Time.now.utc

@dLobatog
Copy link
Member Author

dLobatog commented Feb 8, 2016

@shlomizadok Where exactly do you mean? The goal of the PR is precisely to save everything under UTC for consistency, then only change the time zone in views using the set_timezone method.

@shlomizadok
Copy link
Member

👍 got it.
[test]

@@ -39,7 +39,7 @@ def flavor_with_object
end

def created_at
Time.parse attributes['created']
Time.parse(attributes['created']).utc
Copy link
Contributor

Choose a reason for hiding this comment

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

This might also need a change to use the user's timezone in the VM show view.

Copy link
Member Author

Choose a reason for hiding this comment

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

set_timezone changes the time zone that's then used in prop, which is what shows the time in OpenStack.

https://github.com/theforeman/foreman/blob/develop/app/helpers/compute_resources_vms_helper.rb#L37

Rubocop can enforce what timezone to store in the database ,
so we can ensure everything is stored using UTC and we don't
miss these things in code reviews. When objects are displayed,
they must use the time provided by set_timezone in the
controller.

This is particularly relevant for Trends, Puppet graphs, etc... to
ensure they are stored always properly
@domcleal
Copy link
Contributor

Merged as a977bd3, thanks @dLobatog.

@domcleal domcleal closed this Feb 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants