Permalink
Browse files

Merge remote branch 'origin/handle_timezones_correctly'

Conflicts:
	Gemfile.lock
  • Loading branch information...
2 parents d6985ac + 4a2b9be commit ae99c16760939626ec865648c82f08eaba9dbd9e @fatbusinessman fatbusinessman committed Mar 19, 2013
View
@@ -12,7 +12,7 @@ end
if ENV['CONTENT_MODELS_DEV']
gem "govuk_content_models", :path => '../govuk_content_models'
else
- gem "govuk_content_models", "4.0.0"
+ gem "govuk_content_models", "4.11.0"
end
gem 'erubis'
View
@@ -88,7 +88,7 @@ GEM
railties (>= 3.0.0)
faker (1.0.1)
i18n (~> 0.4)
- faraday (0.8.4)
+ faraday (0.8.6)
multipart-post (~> 1.1)
ffi (1.1.5)
gds-api-adapters (4.1.3)
@@ -104,23 +104,21 @@ GEM
htmlentities (~> 4)
kramdown (~> 0.13.3)
sanitize (= 2.0.3)
- govuk_content_models (4.0.0)
+ govuk_content_models (4.11.0)
bson_ext
differ
gds-api-adapters
gds-sso (>= 3.0.0, < 4.0.0)
govspeak (>= 1.0.1, < 2.0.0)
mongoid (~> 2.4.10)
- multi_json (= 1.3.7)
- omniauth-oauth2 (~> 1.0)
plek
state_machine
has_scope (0.5.1)
hashie (1.2.0)
hike (1.2.1)
htmlentities (4.3.1)
httpauth (0.2.0)
- i18n (0.6.1)
+ i18n (0.6.4)
inherited_resources (1.3.1)
has_scope (~> 0.5.0)
responders (~> 0.6)
@@ -129,8 +127,8 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.7.7)
- jwt (0.1.5)
- multi_json (>= 1.0)
+ jwt (0.1.8)
+ multi_json (>= 1.5)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
@@ -174,18 +172,18 @@ GEM
bundler (>= 1.0.0)
rails (>= 3.2.0)
railties (>= 3.2.0)
- multi_json (1.3.7)
- multipart-post (1.1.5)
+ multi_json (1.6.1)
+ multipart-post (1.2.0)
newrelic_rpm (3.5.5.38)
- nokogiri (1.5.5)
+ nokogiri (1.5.6)
null_logger (0.0.1)
- oauth2 (0.8.0)
+ oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
- omniauth (1.1.1)
+ omniauth (1.1.3)
hashie (~> 1.2)
rack
omniauth-gds (0.0.3)
@@ -304,7 +302,7 @@ DEPENDENCIES
gds-api-adapters (= 4.1.3)
gds-sso (= 3.0.0)
govspeak (= 1.2.0)
- govuk_content_models (= 4.0.0)
+ govuk_content_models (= 4.11.0)
has_scope
inherited_resources
jquery-rails
View
@@ -15,7 +15,7 @@ with other apps, here's how.
### Create a user
publisher$ script/console
- >> User.create name: "Your name", email: "youremail@example.com", uid: Time.now.to_i, version: 1
+ >> User.create name: "Your name", email: "youremail@example.com", uid: Time.zone.now.to_i, version: 1
### Run panopticon using rails s or similar
View
@@ -8,3 +8,5 @@ require 'ci/reporter/rake/test_unit' if Rails.env.test?
Rake.application.options.trace = true
Publisher::Application.load_tasks
+
+task :default => [:test, :check_for_bad_time_handling]
@@ -42,7 +42,7 @@ def produce_fact_check_request_text
end
def friendly_date(date)
- if Time.now - date < 2.days
+ if Time.zone.now - date < 2.days
time_ago_in_words(date) + " ago."
else
date.strftime("%d/%m/%Y %R")
@@ -5,7 +5,7 @@ def publication_front_end_path(publication)
end
def preview_edition_path(edition)
- publication_front_end_path(edition) + "?edition=#{edition.version_number}&cache=#{Time.now().to_i}"
+ publication_front_end_path(edition) + "?edition=#{edition.version_number}&cache=#{Time.zone.now().to_i}"
end
def start_work_path(edition)
@@ -71,7 +71,7 @@ def progress_buttons(edition)
def preview_button(edition)
form_tag(preview_edition_path(edition), :method => :get) do
- hidden_field_tag('cache', Time.now().to_i) +
+ hidden_field_tag('cache', Time.zone.now().to_i) +
hidden_field_tag('edition', edition.version_number) +
submit_tag('Preview', class: 'btn btn-primary btn-large')
end
@@ -1,4 +1,4 @@
-<%= @action.requester.name %> approved fact check "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+<%= @action.requester.name %> approved fact check "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
Comment: <%= @action.comment %>
@@ -1,4 +1,4 @@
-<%= @action.requester.name %> okayed "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+<%= @action.requester.name %> okayed "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
Comment: <%= @action.comment %>
@@ -1,3 +1,3 @@
-"<%= @action.edition.title %>" (<%= @action.edition.format %>) has been assigned to <%= @action.recipient.name %> at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+"<%= @action.edition.title %>" (<%= @action.edition.format %>) has been assigned to <%= @action.recipient.name %> at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
<%= "#{Plek.current.find("private-frontend")}/#{@action.edition.slug}?edition=#{@action.edition.version_number}" %>
@@ -1,3 +1,3 @@
-"<%= @action.edition.title %>" (<%= @action.edition.format %>) created by <%= @action.requester.name %> at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+"<%= @action.edition.title %>" (<%= @action.edition.format %>) created by <%= @action.requester.name %> at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
<%= "#{Plek.current.find("private-frontend")}/#{@action.edition.slug}?edition=#{@action.edition.version_number}" %>
@@ -1,3 +1,3 @@
-New version of "<%= @action.edition.title %>" (<%= @action.edition.format %>) created by <%= @action.requester.name %> at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+New version of "<%= @action.edition.title %>" (<%= @action.edition.format %>) created by <%= @action.requester.name %> at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
<%= "#{Plek.current.find("private-frontend")}/#{@action.edition.slug}?edition=#{@action.edition.version_number}" %>
@@ -1,3 +1,3 @@
-<%= @action.requester.name %> published "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+<%= @action.requester.name %> published "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
<%= "#{Plek.current.find("private-frontend")}/#{@action.edition.slug}" %>
@@ -1,4 +1,4 @@
-Fact check response received for "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+Fact check response received for "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
<%= "#{Plek.current.find("private-frontend")}/#{@action.edition.slug}?edition=#{@action.edition.version_number}" %>
@@ -1,4 +1,4 @@
-"<%= @action.edition.title %>" (<%= @action.edition.format %>) reviewed by <%= @action.requester.name %> at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+"<%= @action.edition.title %>" (<%= @action.edition.format %>) reviewed by <%= @action.requester.name %> at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
Further amends required:
<%= @action.comment %>
@@ -2,7 +2,7 @@ Please review "<%= @action.edition.title %>" (<%= @action.edition.format %>)
Comment: <%= @action.comment %>
-Requested by <%= @action.requester.name %> at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+Requested by <%= @action.requester.name %> at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
View:
<%= "#{Plek.current.find("private-frontend")}/#{@action.edition.slug}?edition=#{@action.edition.version_number}" %>
@@ -1,4 +1,4 @@
-Fact check requested for "<%= @action.edition.title %>" (<%= @action.edition.format %>) by <%= @action.requester.name %> at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+Fact check requested for "<%= @action.edition.title %>" (<%= @action.edition.format %>) by <%= @action.requester.name %> at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
Sent to: <%= @action.email_addresses %>
2nd eyes: <%= @action.requester.name %>
@@ -1,3 +1,3 @@
-<%= @action.requester.name %> skipped fact check for "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+<%= @action.requester.name %> skipped fact check for "<%= @action.edition.title %>" (<%= @action.edition.format %>) at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
<%= "#{Plek.current.find("private-frontend")}/#{@action.edition.slug}?edition=#{@action.edition.version_number}" %>
@@ -1,3 +1,3 @@
-Work was started on "<%= @action.edition.title %>" (<%= @action.edition.format %>) by <%= @action.requester.name %> at <%=Time.now.strftime("%R on %d/%m/%Y") %>
+Work was started on "<%= @action.edition.title %>" (<%= @action.edition.format %>) by <%= @action.requester.name %> at <%=Time.zone.now.strftime("%R on %d/%m/%Y") %>
<%= "#{Plek.current.find("private-frontend")}/#{@action.edition.slug}?edition=#{@action.edition.version_number}" %>
View
@@ -44,7 +44,7 @@ class Application < Rails::Application
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = 'Central Time (US & Canada)'
+ config.time_zone = 'London'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
View
@@ -1,12 +1,15 @@
+# This file is overwritten by one in alphagov-deployment at deploy time
development:
host: localhost
database: govuk_content_development
persist_in_safe_mode: true
+ use_activesupport_time_zone: true
test:
host: localhost
# Don't want this interfering with a concurrent Panopticon test run
database: govuk_content_publisher_test
+ use_activesupport_time_zone: true
# set these environment variables on your prod server
production:
@@ -15,6 +18,7 @@ production:
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
+ use_activesupport_time_zone: true
# slaves:
# - host: slave1.local
# port: 27018
@@ -81,7 +81,7 @@ def import row
def add_workflow(user, edition)
type = Action.const_get(Action::CREATE.to_s.upcase)
action = edition.new_action(user, type, {})
- user.record_note(edition, "Imported via BusinessSupportContentImporter: #{Time.now.to_s(:db)}")
+ user.record_note(edition, "Imported via BusinessSupportContentImporter: #{Time.zone.now.to_s(:db)}")
end
def formatted_result(import=true)
@@ -0,0 +1,25 @@
+task :check_for_bad_time_handling do
+ directories = Dir.glob(File.join(Rails.root, '**', '*.rb'))
+ matching_files = directories.select do |filename|
+ match = false
+ File.open(filename) do |file|
+ match = file.grep(%r{Time\.(now|utc|parse)}).any?
+ end
+ match
+ end
+ if matching_files.any?
+ raise <<-MSG
+
+Avoid issues with daylight-savings time by always building instances of
+TimeWithZone and not Time. Use methods like:
+ Time.zone.now, Time.zone.parse, n.days.ago, m.hours.from_now, etc
+
+in preference to methods like:
+ Time.now, Time.utc, Time.parse, etc
+
+Files that contain bad Time handling:
+ #{matching_files.join("\n ")}
+
+MSG
+ end
+end
@@ -27,7 +27,7 @@ def sample_processor(body_text = "I approve")
end
def sample_publication
- FactoryGirl.create(:guide_edition, title: 'Hello', slug: "hello-#{Time.now.to_i}")
+ FactoryGirl.create(:guide_edition, title: 'Hello', slug: "hello-#{Time.zone.now.to_i}")
end
test "processing returns false if the publication isn't found" do

0 comments on commit ae99c16

Please sign in to comment.