Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Use London timezone, not UTC
Browse files Browse the repository at this point in the history
Also, test for inappropriate uses of time without zone.

The changes to mongoid.yml need to be reflected in alphagov-deployment.
  • Loading branch information
jamiecobbett committed Mar 15, 2013
1 parent 9b37baa commit 1261337
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -32,7 +32,7 @@ gem 'lograge', '~> 0.1.0'
if ENV['CONTENT_MODELS_DEV']
gem "govuk_content_models", path: '../govuk_content_models'
else
gem "govuk_content_models", "4.10.2"
gem "govuk_content_models", "4.11.0"
end

if ENV['BUNDLE_DEV']
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -120,7 +120,7 @@ GEM
htmlentities (~> 4)
kramdown (~> 0.13.3)
sanitize (= 2.0.3)
govuk_content_models (4.10.2)
govuk_content_models (4.11.0)
bson_ext
differ
gds-api-adapters
Expand All @@ -142,7 +142,7 @@ GEM
jquery-rails
railties (>= 3.1.0)
json (1.7.7)
jwt (0.1.7)
jwt (0.1.8)
multi_json (>= 1.5)
kgio (2.7.4)
kramdown (0.13.8)
Expand Down Expand Up @@ -326,7 +326,7 @@ DEPENDENCIES
gds-api-adapters (= 4.1.3)
gds-sso (= 3.0.0)
gelf
govuk_content_models (= 4.10.2)
govuk_content_models (= 4.11.0)
jquery-rails (= 2.0.2)
jquery-ui-rails (= 3.0.1)
launchy
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -7,3 +7,5 @@ ENV["GOVUK_WEBSITE_ROOT"] = ENV.fetch("GOVUK_WEBSITE_ROOT", "http://www.dev.gov.
require File.expand_path('../config/application', __FILE__)

Panopticon::Application.load_tasks

task :default => [:test, :check_for_bad_time_handling]
2 changes: 1 addition & 1 deletion config/application.rb
Expand Up @@ -38,7 +38,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]
Expand Down
4 changes: 4 additions & 0 deletions config/mongoid.yml
@@ -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 Publisher test run
database: govuk_content_panopticon_test
use_activesupport_time_zone: true

# set these environment variables on your prod server
production:
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions lib/tasks/check_for_bad_time_handling.rake
@@ -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

0 comments on commit 1261337

Please sign in to comment.