diff --git a/app/models/symbolize_json.rb b/app/models/symbolize_json.rb index fade21163..06b036c14 100644 --- a/app/models/symbolize_json.rb +++ b/app/models/symbolize_json.rb @@ -20,7 +20,7 @@ def self.symbolize(value) new_hash[k.to_sym] = symbolize(v) end when ActiveSupport::TimeWithZone - value.iso8601 + value.utc.iso8601 else value end diff --git a/app/presenters/edition_presenter.rb b/app/presenters/edition_presenter.rb index b06b6b577..6cdd78158 100644 --- a/app/presenters/edition_presenter.rb +++ b/app/presenters/edition_presenter.rb @@ -141,7 +141,7 @@ def withdrawal_notice unpublishing = edition.unpublishing if unpublishing && unpublishing.withdrawal? - withdrawn_at = (unpublishing.unpublished_at || unpublishing.created_at).iso8601 + withdrawn_at = (unpublishing.unpublished_at || unpublishing.created_at).utc.iso8601 { withdrawn_notice: { explanation: unpublishing.explanation, diff --git a/app/presenters/gone_presenter.rb b/app/presenters/gone_presenter.rb index 857026bd8..760543de5 100644 --- a/app/presenters/gone_presenter.rb +++ b/app/presenters/gone_presenter.rb @@ -46,7 +46,7 @@ def present base_path:, locale:, publishing_app:, - public_updated_at: public_updated_at&.iso8601, + public_updated_at: public_updated_at&.utc&.iso8601, details: { explanation:, alternative_path:, diff --git a/app/presenters/redirect_presenter.rb b/app/presenters/redirect_presenter.rb index 7de578bee..a476f101a 100644 --- a/app/presenters/redirect_presenter.rb +++ b/app/presenters/redirect_presenter.rb @@ -76,6 +76,6 @@ def formatted_dates public_updated_at:, first_published_at:, }.compact - .transform_values(&:iso8601) + .transform_values { |v| v.utc.iso8601 } end end diff --git a/app/queries/get_expanded_links.rb b/app/queries/get_expanded_links.rb index a434c2368..a92b978a0 100644 --- a/app/queries/get_expanded_links.rb +++ b/app/queries/get_expanded_links.rb @@ -59,7 +59,7 @@ def stored_links_response(expanded_links) def response(expanded_links, generated_date, version = nil) response = { - generated: generated_date.iso8601, + generated: generated_date.utc.iso8601, expanded_links:, } response[:version] = version if version diff --git a/app/queries/get_link_changes.rb b/app/queries/get_link_changes.rb index a88510269..b9bf47e0a 100644 --- a/app/queries/get_link_changes.rb +++ b/app/queries/get_link_changes.rb @@ -23,7 +23,7 @@ def as_hash end { - link_changes: results, + link_changes: SymbolizeJSON.symbolize(results), } end diff --git a/app/queries/keyset_pagination.rb b/app/queries/keyset_pagination.rb index 96699ab81..00f71a589 100644 --- a/app/queries/keyset_pagination.rb +++ b/app/queries/keyset_pagination.rb @@ -98,7 +98,9 @@ def presented_fields def key_for_record(record) key_fields.map do |k| value = record[k] - next value.iso8601(6) if value.respond_to?(:iso8601) + if value.is_a?(Time) || value.is_a?(Date) + next value.utc.iso8601(6) + end value.to_s end diff --git a/lib/tasks/csv_report.rake b/lib/tasks/csv_report.rake index a7e00ecc5..540ef2de7 100644 --- a/lib/tasks/csv_report.rake +++ b/lib/tasks/csv_report.rake @@ -41,20 +41,22 @@ namespace :csv_report do csv << %w[published_at base_path content_id locale title document_type update_type first_publishing] - query = Edition.joins(:document) - .where(published_at: from_time...until_time) - .where.not(update_type: :republish) - .order(published_at: :asc) - .pluck(:published_at, - :base_path, - "documents.content_id", - "documents.locale", - :title, - :document_type, - :update_type, - Arel.sql("(user_facing_version = 1)")) - - query.each { |row| csv << row } + Time.use_zone("UTC") do + query = Edition.joins(:document) + .where(published_at: from_time...until_time) + .where.not(update_type: :republish) + .order(published_at: :asc) + .pluck(:published_at, + :base_path, + "documents.content_id", + "documents.locale", + :title, + :document_type, + :update_type, + Arel.sql("(user_facing_version = 1)")) + + query.each { |row| csv << row } + end end desc "Prints a CSV of all editions that were unpublished between the from and until timestamp" @@ -68,18 +70,20 @@ namespace :csv_report do csv << %w[unpublished_at base_path content_id locale title document_type unpublishing_type] - query = Unpublishing.joins({ edition: :document }) - .where(created_at: from_time...until_time) - .where.not(type: "substitute") - .order(created_at: :asc) - .pluck(:created_at, - "editions.base_path", - "documents.content_id", - "documents.locale", - "editions.title", - "editions.document_type", - :type) - - query.each { |row| csv << row } + Time.use_zone("UTC") do + query = Unpublishing.joins({ edition: :document }) + .where(created_at: from_time...until_time) + .where.not(type: "substitute") + .order(created_at: :asc) + .pluck(:created_at, + "editions.base_path", + "documents.content_id", + "documents.locale", + "editions.title", + "editions.document_type", + :type) + + query.each { |row| csv << row } + end end end diff --git a/spec/clients/content_store_writer_spec.rb b/spec/clients/content_store_writer_spec.rb index 6b0a9ec6b..4919b00dd 100644 --- a/spec/clients/content_store_writer_spec.rb +++ b/spec/clients/content_store_writer_spec.rb @@ -18,7 +18,7 @@ let(:publish_intent) do { - publish_time: Time.zone.now.iso8601, + publish_time: Time.zone.now.utc.iso8601, publishing_app: "whitehall", rendering_app: "whitehall-frontend", routes: [ diff --git a/spec/commands/v2/put_content_spec.rb b/spec/commands/v2/put_content_spec.rb index 9fa036219..bb2869104 100644 --- a/spec/commands/v2/put_content_spec.rb +++ b/spec/commands/v2/put_content_spec.rb @@ -156,13 +156,13 @@ context "when the draft does not exist" do context "with a provided last_edited_at" do it "stores the provided timestamp" do - last_edited_at = 1.year.ago + last_edited_at = 1.year.ago.utc described_class.call(payload.merge(last_edited_at: last_edited_at.iso8601)) edition = Edition.last - expect(edition.last_edited_at.iso8601).to eq(last_edited_at.iso8601) + expect(edition.last_edited_at.utc.iso8601).to eq(last_edited_at.iso8601) end end @@ -172,7 +172,7 @@ edition = Edition.last - expect(edition.last_edited_at.iso8601).to eq(Time.zone.now.iso8601) + expect(edition.last_edited_at.utc.iso8601).to eq(Time.zone.now.utc.iso8601) end end @@ -214,7 +214,7 @@ %w[minor major republish].each do |update_type| context "with update_type of #{update_type}" do it "stores the provided timestamp" do - last_edited_at = 1.year.ago + last_edited_at = 1.year.ago.utc described_class.call( payload.merge( @@ -223,7 +223,7 @@ ), ) - expect(edition.reload.last_edited_at.iso8601).to eq(last_edited_at.iso8601) + expect(edition.reload.last_edited_at.utc.iso8601).to eq(last_edited_at.iso8601) end end end @@ -233,7 +233,7 @@ Timecop.freeze do described_class.call(payload) - expect(edition.reload.last_edited_at.iso8601).to eq(Time.zone.now.iso8601) + expect(edition.reload.last_edited_at.utc.iso8601).to eq(Time.zone.now.utc.iso8601) end end diff --git a/spec/factories/content_item_requests.rb b/spec/factories/content_item_requests.rb index 912e391f7..9be19b044 100644 --- a/spec/factories/content_item_requests.rb +++ b/spec/factories/content_item_requests.rb @@ -6,7 +6,7 @@ description { "Test description" } document_type { "answer" } schema_name { "answer" } - public_updated_at { Time.zone.now.iso8601 } + public_updated_at { Time.zone.now.utc.iso8601 } publishing_app { "publisher" } rendering_app { "frontend" } locale { "en" } diff --git a/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb b/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb index 19ab31d95..a5681bb8a 100644 --- a/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb +++ b/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb @@ -79,8 +79,8 @@ put "/v2/content/#{content_id}", params: payload.to_json edition = Edition.last - expect(edition.major_published_at.iso8601) - .to eq(major_published_at.iso8601) + expect(edition.major_published_at.utc.iso8601) + .to eq(major_published_at.utc.iso8601) end end @@ -94,7 +94,7 @@ put "/v2/content/#{content_id}", params: payload.to_json edition = Edition.last - expect(edition.first_published_at.iso8601).to eq(new_first_published_at) + expect(edition.first_published_at.utc.iso8601).to eq(new_first_published_at) end end diff --git a/spec/lib/data_hygiene/document_status_checker_spec.rb b/spec/lib/data_hygiene/document_status_checker_spec.rb index 6917f4662..141a48b0a 100644 --- a/spec/lib/data_hygiene/document_status_checker_spec.rb +++ b/spec/lib/data_hygiene/document_status_checker_spec.rb @@ -22,7 +22,7 @@ context "and there is an old content item" do let(:content_item) do content_item_for_base_path(base_path).merge( - "updated_at" => (edition.published_at - 1).iso8601, + "updated_at" => (edition.published_at - 1).utc.iso8601, ) end before { stub_content_store_has_item(base_path, content_item) } @@ -32,7 +32,7 @@ context "and there is a recent content item" do let(:content_item) do content_item_for_base_path(base_path).merge( - "updated_at" => (edition.published_at + 1).iso8601, + "updated_at" => (edition.published_at + 1).utc.iso8601, ) end before { stub_content_store_has_item(base_path, content_item) } diff --git a/spec/models/change_note_spec.rb b/spec/models/change_note_spec.rb index c9b25f00c..3fb4d2025 100644 --- a/spec/models/change_note_spec.rb +++ b/spec/models/change_note_spec.rb @@ -30,7 +30,7 @@ expect { subject }.to change { ChangeNote.count }.by(1) result = ChangeNote.last expect(result.note).to eq "Excellent" - expect(result.public_timestamp.iso8601).to eq Time.zone.now.iso8601 + expect(result.public_timestamp.utc.iso8601).to eq Time.zone.now.utc.iso8601 end end @@ -45,7 +45,7 @@ context "payload contains public_updated_at" do it "sets the change note public_timestamp to public_updated_at time" do - time = Time.zone.yesterday + time = Time.zone.now.utc.yesterday payload[:public_updated_at] = time described_class.create_from_edition(payload, edition) diff --git a/spec/models/symbolize_json_spec.rb b/spec/models/symbolize_json_spec.rb index 6392d47f1..95b4a6aaa 100644 --- a/spec/models/symbolize_json_spec.rb +++ b/spec/models/symbolize_json_spec.rb @@ -10,6 +10,15 @@ expect(subject.public_updated_at).to eq(Date.new(2000, 1, 1)) end + it "emits times in different timezones as UTC" do + subject.public_updated_at = Time.utc(2000, 1, 1).in_time_zone("Eastern Time (US & Canada)") + + subject.save! + subject.reload + + expect(subject.public_updated_at).to eq(Time.utc(2000, 1, 1)) + end + context "json columns" do it "symbolizes hashes" do subject.details = { "foo" => "bar" } diff --git a/spec/presenters/edition_presenter_spec.rb b/spec/presenters/edition_presenter_spec.rb index 1a41e7927..240fb4af3 100644 --- a/spec/presenters/edition_presenter_spec.rb +++ b/spec/presenters/edition_presenter_spec.rb @@ -178,7 +178,7 @@ expected.merge( withdrawn_notice: { explanation: unpublishing.explanation, - withdrawn_at: unpublishing.created_at.iso8601, + withdrawn_at: unpublishing.created_at.utc.iso8601, }, ), ), @@ -203,7 +203,7 @@ expected.merge( withdrawn_notice: { explanation: unpublishing.explanation, - withdrawn_at: unpublishing.unpublished_at.iso8601, + withdrawn_at: unpublishing.unpublished_at.utc.iso8601, }, ), ), diff --git a/spec/presenters/gone_presenter_spec.rb b/spec/presenters/gone_presenter_spec.rb index 6ab88912b..1ab0f78d9 100644 --- a/spec/presenters/gone_presenter_spec.rb +++ b/spec/presenters/gone_presenter_spec.rb @@ -11,6 +11,15 @@ expect(subject).to be_valid_against_notification_schema("gone") end + context "with unpublished_at set" do + let(:unpublishing) { create(:unpublishing, unpublished_at: Time.utc(2000, 1, 1)) } + let(:edition) { unpublishing.edition } + + it "presents public_updated_at as the unpublishings unpublished_at time in UTC" do + expect(subject[:public_updated_at]).to eql(unpublishing.unpublished_at.utc.iso8601) + end + end + context "with a nil base_path" do let(:edition) { create(:gone_unpublished_edition, base_path: nil) } diff --git a/spec/presenters/queries/content_item_presenter_spec.rb b/spec/presenters/queries/content_item_presenter_spec.rb index 30bb6e05b..bf81aeb05 100644 --- a/spec/presenters/queries/content_item_presenter_spec.rb +++ b/spec/presenters/queries/content_item_presenter_spec.rb @@ -91,7 +91,7 @@ "type" => unpublishing.type, "explanation" => unpublishing.explanation, "alternative_path" => unpublishing.alternative_path, - "unpublished_at" => unpublishing.unpublished_at.rfc3339, + "unpublished_at" => unpublishing.unpublished_at.utc.rfc3339, ), ) end diff --git a/spec/presenters/redirect_presenter_spec.rb b/spec/presenters/redirect_presenter_spec.rb index 454754ad4..a43302580 100644 --- a/spec/presenters/redirect_presenter_spec.rb +++ b/spec/presenters/redirect_presenter_spec.rb @@ -18,7 +18,7 @@ end it "includes the public updated at" do - expect(subject[:public_updated_at]).to eq(edition.unpublishing.created_at.iso8601) + expect(subject[:public_updated_at]).to eq(edition.unpublishing.created_at.utc.iso8601) end end @@ -34,11 +34,11 @@ end it "includes the first published at" do - expect(subject[:first_published_at]).to eq(edition.first_published_at.iso8601) + expect(subject[:first_published_at]).to eq(edition.first_published_at.utc.iso8601) end it "includes the public updated at" do - expect(subject[:public_updated_at]).to eq(edition.public_updated_at.iso8601) + expect(subject[:public_updated_at]).to eq(edition.public_updated_at.utc.iso8601) end end end diff --git a/spec/queries/get_content_collection_spec.rb b/spec/queries/get_content_collection_spec.rb index 5a6e57180..da09acf61 100644 --- a/spec/queries/get_content_collection_spec.rb +++ b/spec/queries/get_content_collection_spec.rb @@ -604,10 +604,10 @@ describe "result order" do before do - create(:edition, base_path: "/c4", title: "D", public_updated_at: "2014-06-14") - create(:edition, base_path: "/c1", title: "A", public_updated_at: "2014-06-13") - create(:edition, base_path: "/c3", title: "C", public_updated_at: "2014-06-17") - create(:edition, base_path: "/c2", title: "B", public_updated_at: "2014-06-15") + create(:edition, base_path: "/c4", title: "D", public_updated_at: Time.utc(2014, 6, 14)) + create(:edition, base_path: "/c1", title: "A", public_updated_at: Time.utc(2014, 6, 13)) + create(:edition, base_path: "/c3", title: "C", public_updated_at: Time.utc(2014, 6, 17)) + create(:edition, base_path: "/c2", title: "B", public_updated_at: Time.utc(2014, 6, 15)) end it "returns editions in default order" do diff --git a/spec/queries/get_expanded_links_spec.rb b/spec/queries/get_expanded_links_spec.rb index d4ac82546..7a1cb9530 100644 --- a/spec/queries/get_expanded_links_spec.rb +++ b/spec/queries/get_expanded_links_spec.rb @@ -44,7 +44,7 @@ it "returns the data from expanded links" do expect(result).to match( - generated: updated_at.iso8601, + generated: updated_at.utc.iso8601, expanded_links: expanded_links.as_json, ) end diff --git a/spec/queries/get_link_changes_spec.rb b/spec/queries/get_link_changes_spec.rb index 01d2503ea..f1ef7cd76 100644 --- a/spec/queries/get_link_changes_spec.rb +++ b/spec/queries/get_link_changes_spec.rb @@ -1,7 +1,7 @@ RSpec.describe Queries::GetLinkChanges do describe "#as_hash" do it "returns the link changes with the correct data" do - create(:link_change, link_type: "taxons") + link_change = create(:link_change, link_type: "taxons") result = Queries::GetLinkChanges.new(link_types: "taxons").as_hash @@ -10,6 +10,7 @@ expect(change.keys).to match_array( %i[source target link_type change user_uid created_at], ) + expect(change[:created_at]).to eql(link_change.created_at.utc.iso8601) end it "expands the source and target" do diff --git a/spec/requests/publish_intent_requests_spec.rb b/spec/requests/publish_intent_requests_spec.rb index 57d67aa42..5f88a99bf 100644 --- a/spec/requests/publish_intent_requests_spec.rb +++ b/spec/requests/publish_intent_requests_spec.rb @@ -1,7 +1,7 @@ RSpec.describe "Publish intent requests", type: :request do let(:content_item) do { - publish_time: (Time.zone.now + 3.hours).iso8601, + publish_time: (Time.zone.now.utc + 3.hours).iso8601, publishing_app: "publisher", rendering_app: "frontend", routers: [ diff --git a/spec/requests/unpublishing_spec.rb b/spec/requests/unpublishing_spec.rb index 58f3f2a35..b5d80b75c 100644 --- a/spec/requests/unpublishing_spec.rb +++ b/spec/requests/unpublishing_spec.rb @@ -29,7 +29,7 @@ content_item: a_hash_including( withdrawn_notice: { explanation: "Test withdrawal", - withdrawn_at: Time.zone.now.iso8601, + withdrawn_at: Time.zone.now.utc.iso8601, }, ), } @@ -107,8 +107,8 @@ base_path:, locale: edition.locale, publishing_app: edition.publishing_app, - public_updated_at: Time.zone.now.iso8601, - first_published_at: edition.first_published_at.iso8601, + public_updated_at: Time.zone.now.utc.iso8601, + first_published_at: edition.first_published_at.utc.iso8601, redirects: [ { path: base_path,