Skip to content

Commit

Permalink
Merge pull request #320 from alphagov/timezones
Browse files Browse the repository at this point in the history
Use London timezone
  • Loading branch information
fofr authored Apr 11, 2017
2 parents 64f4288 + 737211f commit d3a7e23
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/presenters/consultation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def opening_date
end

def opening_date_midnight?
Time.parse(opening_date_time).strftime("%l:%M%P") == "12:00am"
Time.zone.parse(opening_date_time).strftime("%l:%M%P") == "12:00am"
end

def closing_date
Expand Down Expand Up @@ -116,7 +116,7 @@ def attachment_url
private

def display_date_and_time(date, rollback_midnight = false)
time = Time.parse(date)
time = Time.zone.parse(date)
date_format = "%-e %B %Y"
time_format = "%l:%M%P"

Expand Down
2 changes: 1 addition & 1 deletion app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def taxonomy_sidebar
private

def display_date(timestamp, format = "%-d %B %Y")
I18n.l(Time.parse(timestamp), format: format) if timestamp
I18n.l(Time.zone.parse(timestamp), format: format) if timestamp
end

def sorted_locales(translations)
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def groups
def group_document_links(group)
group_documents(group).map do |link|
{
public_updated_at: Time.parse(link["public_updated_at"]),
public_updated_at: Time.zone.parse(link["public_updated_at"]),
document_type: link["document_type"],
title: link["title"],
base_path: link["base_path"]
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/statistics_announcement_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def national_statistics?

def cancellation_date
cancelled_at = content_item["details"]["cancelled_at"]
DateTime.parse(cancelled_at).strftime("%e %B %Y %-l:%M%P")
Time.zone.parse(cancelled_at).strftime("%e %B %Y %-l:%M%P")
end

def cancelled?
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/topical_event_about_page_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def parent
return nil unless super
topical_event_end_date = super.dig("details", "end_date")

if topical_event_end_date && DateTime.parse(topical_event_end_date) <= Date.today
if topical_event_end_date && Time.zone.parse(topical_event_end_date) <= Time.zone.today
super.merge("title" => "#{super['title']} (Archived)")
else
super
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/travel_advice_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def metadata
updated_at = content_item['details']['updated_at']

other = {
"Still current at" => I18n.l(Time.now, format: "%-d %B %Y"),
"Still current at" => I18n.l(Time.zone.now, format: "%-d %B %Y"),
"Updated" => display_date(reviewed_at || updated_at),
}

Expand Down
2 changes: 1 addition & 1 deletion app/presenters/updatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def reverse_chronological_change_history

def any_updates?
if public_updated_at && first_public_at
DateTime.parse(public_updated_at) != DateTime.parse(first_public_at)
Time.zone.parse(public_updated_at) != Time.zone.parse(first_public_at)
else
false
end
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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'

# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/lib)
Expand Down
11 changes: 7 additions & 4 deletions test/integration/consultation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ class ConsultationTest < ActionDispatch::IntegrationTest
setup_and_visit_content_item('open_consultation')

assert page.has_text?("Open consultation")
assert page.has_text?("closes at 4pm on 16 December 2216")
assert page.has_text?("closes at 3pm on 16 December 2216")
end

test "unopened consultation" do
setup_and_visit_content_item('unopened_consultation')

assert page.has_text?("Consultation")
assert page.has_css?('.consultation-notice', text: "This consultation opens at 2pm on 5 October 2200")
assert page.has_text?("It closes at 5pm on 31 October 2210")

# There’s no daylight savings after 2037
# http://timezonesjl.readthedocs.io/en/stable/faq/#far-future-zoneddatetime-with-variabletimezone
assert page.has_css?('.consultation-notice', text: "This consultation opens at 1pm on 5 October 2200")
assert page.has_text?("It closes at 4pm on 31 October 2210")
end

test "closed consultation pending outcome" do
Expand All @@ -59,7 +62,7 @@ class ConsultationTest < ActionDispatch::IntegrationTest
assert page.has_css?('.consultation-notice', text: "We are analysing your feedback")

assert page.has_text?("ran from")
assert page.has_text?("2pm on 5 September 2016 to 5pm on 31 October 2016")
assert page.has_text?("2pm on 5 September 2016 to 4pm on 31 October 2016")
end

test "consultation outcome" do
Expand Down
19 changes: 12 additions & 7 deletions test/presenters/consultation_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ def format_name
end

test 'presents friendly dates for opening and closing dates, including time' do
assert_equal "10am on 4 November 2016", presented_item("open_consultation").opening_date
assert_equal "4pm on 16 December 2216", presented_item("open_consultation").closing_date
schema = schema_item("open_consultation")
schema['details']['opening_date'] = "2016-11-04T10:00:00+00:00"
schema['details']['closing_date'] = "2216-12-16T16:00:00+00:00"
presented = presented_item("open_consultation", schema)

assert_equal "10am on 4 November 2016", presented.opening_date
assert_equal "4pm on 16 December 2216", presented.closing_date
end

test 'presents closing dates at 12am as 11:59pm on the day before' do
schema = schema_item("open_consultation")
schema['details']['opening_date'] = "2016-11-03T00:01:00+01:00"
schema['details']['closing_date'] = "2016-11-04T00:00:00+01:00"
schema['details']['opening_date'] = "2016-11-03T00:01:00+00:00"
schema['details']['closing_date'] = "2016-11-04T00:00:00+00:00"
presented = presented_item("open_consultation", schema)

assert_equal "12:01am on 3 November 2016", presented.opening_date
Expand All @@ -28,16 +33,16 @@ def format_name

test 'presents opening dates at 12am as the date without a time' do
schema = schema_item("open_consultation")
schema['details']['opening_date'] = "2016-11-03T00:00:00+01:00"
schema['details']['closing_date'] = "2016-11-04T00:00:00+01:00"
schema['details']['opening_date'] = "2016-11-03T00:00:00+00:00"
schema['details']['closing_date'] = "2016-11-04T00:00:00+00:00"
presented = presented_item("open_consultation", schema)

assert_equal "3 November 2016", presented.opening_date
end

test 'presents 12pm as midday' do
schema = schema_item("open_consultation")
schema['details']['opening_date'] = "2016-11-04T12:00:00+01:00"
schema['details']['opening_date'] = "2016-11-04T12:00:00+00:00"
presented = presented_item("open_consultation", schema)

assert_equal "midday on 4 November 2016", presented.opening_date
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/document_collection_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PresentedDocumentCollection < TestCase
test 'presents an ordered list of group documents' do
documents = [
{
public_updated_at: Time.parse("2007-03-16 15:00:02 +0000"),
public_updated_at: Time.zone.parse("2007-03-16 15:00:02 +0000"),
document_type: "guidance",
title: "National standard for driving cars and light vans",
base_path: "/government/publications/national-standard-for-driving-cars-and-light-vans"
Expand Down

0 comments on commit d3a7e23

Please sign in to comment.