Skip to content

Commit

Permalink
use correct export date format
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 8, 2020
1 parent acee21c commit f95c791
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class ExportController < ApplicationController
include ActionController::MimeResponds

EXPORT_DATE_FORMAT = "%d/%m/%YT%H:%M:%S.%3NUTC%:z"

before_action :authenticate_user_with_basic_auth!

def contacts
Expand Down Expand Up @@ -163,9 +161,9 @@ def organizations
billingCountryCode: provider.billing_information.country,
twitter: provider.twitter_handle,
rorId: provider.ror_id,
created: provider.created,
modified: provider.updated,
deleted: provider.deleted_at.present? ? provider.deleted_at : nil,
created: export_date(provider.created),
modified: export_date(provider.updated),
deleted: provider.deleted_at.present? ? export_date(provider.deleted_at) : nil,
}.values

csv += CSV.generate_line row
Expand Down Expand Up @@ -252,9 +250,9 @@ def repositories
serviceContactEmail: client.service_contact.email,
serviceContactGivenName: client.service_contact.given_name,
serviceContactFamilyName: client.service_contact.family_name,
created: client.created,
modified: client.updated,
deleted: client.deleted_at.present? ? client.deleted_at : nil,
created: export_date(client.created),
modified: export_date(client.updated),
deleted: client.deleted_at.present? ? export_date(client.deleted_at) : nil,
doisCountCurrentYear: client_totals[client.uid] ? client_totals[client.uid]["this_year"] : nil,
doisCountPreviousYear: client_totals[client.uid] ? client_totals[client.uid]["last_year"] : nil,
doisCountTotal: client_totals[client.uid] ? client_totals[client.uid]["count"] : nil
Expand All @@ -272,4 +270,8 @@ def repositories
render json: { "errors" => { "title" => message }}.to_json, status: :bad_request
end
end

def export_date(date)
DateTime.strptime(date, "%Y-%m-%dT%H:%M:%S").strftime("%d/%m/%YT%H:%M:%S.%3NUTC%:z")
end
end
2 changes: 1 addition & 1 deletion spec/requests/exports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

it 'returns organizations', vcr: false do
get "/export/organizations", nil, admin_headers

puts last_response.body
expect(last_response.status).to eq(200)
csv = last_response.body.lines
expect(csv.length).to eq(3)
Expand Down

0 comments on commit f95c791

Please sign in to comment.