Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Remove config/initializers/time_formats.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
dazza-codes committed Oct 27, 2016
1 parent ec4ea9b commit c8e206c
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 32 deletions.
10 changes: 5 additions & 5 deletions app/adapters/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def map_simple(model_field, public_field)
# Register a one-to-one mapping of a date field.
# @param [Symbol] model_field
# @param [Symbol] public_field
# @param [String] date_format The Date format to use.
def map_date(model_field, public_field, date_format)
# @param [String] date_format The Date format to use ("%Y-%m-%dT%H:%M:%SZ").
def map_date(model_field, public_field, date_format = "%Y-%m-%dT%H:%M:%SZ")
map_from_public public_field do |value|
{model_field => time_from_public(value)}
end
Expand Down Expand Up @@ -165,9 +165,9 @@ def from_public(public)

def time_from_public(time)
if time.is_a? String
return time_from_string(time)
Time.zone.parse(time)
else
return time
time
end
end

Expand Down Expand Up @@ -201,4 +201,4 @@ def to_bool(value)
end


end
end
4 changes: 2 additions & 2 deletions app/adapters/bag_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class BagAdapter < ::AbstractAdapter

map_date :created_at, :created_at, Time::DATE_FORMATS[:dpn]
map_date :updated_at, :updated_at, Time::DATE_FORMATS[:dpn]
map_date :created_at, :created_at
map_date :updated_at, :updated_at

map_simple :uuid, :uuid
map_simple :local_id, :local_id
Expand Down
4 changes: 2 additions & 2 deletions app/adapters/fixity_check_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class FixityCheckAdapter < ::AbstractAdapter
map_date :created_at, :created_at, Time::DATE_FORMATS[:dpn]
map_date :fixity_at, :fixity_at, Time::DATE_FORMATS[:dpn]
map_date :created_at, :created_at
map_date :fixity_at, :fixity_at
map_simple :fixity_check_id, :fixity_check_id
map_bool :success, :success
map_belongs_to :bag, :bag, sub_method: :uuid
Expand Down
2 changes: 1 addition & 1 deletion app/adapters/ingest_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class IngestAdapter < ::AbstractAdapter
map_date :created_at, :created_at, Time::DATE_FORMATS[:dpn]
map_date :created_at, :created_at

map_simple :ingest_id, :ingest_id
map_belongs_to :bag, :bag, sub_method: :uuid
Expand Down
4 changes: 2 additions & 2 deletions app/adapters/member_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class MemberAdapter < ::AbstractAdapter
map_date :created_at, :created_at, Time::DATE_FORMATS[:dpn]
map_date :updated_at, :updated_at, Time::DATE_FORMATS[:dpn]
map_date :created_at, :created_at
map_date :updated_at, :updated_at

map_simple :member_id, :member_id
map_simple :name, :name
Expand Down
2 changes: 1 addition & 1 deletion app/adapters/message_digest_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class MessageDigestAdapter < ::AbstractAdapter
map_date :created_at, :created_at, Time::DATE_FORMATS[:dpn]
map_date :created_at, :created_at
map_simple :value, :value
map_belongs_to :bag, :bag, sub_method: :uuid
map_belongs_to :node, :node, sub_method: :namespace
Expand Down
4 changes: 2 additions & 2 deletions app/adapters/node_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class NodeAdapter < ::AbstractAdapter
map_date :created_at, :created_at, Time::DATE_FORMATS[:dpn]
map_date :updated_at, :updated_at, Time::DATE_FORMATS[:dpn]
map_date :created_at, :created_at
map_date :updated_at, :updated_at

map_simple :name, :name
map_simple :namespace, :namespace
Expand Down
4 changes: 2 additions & 2 deletions app/adapters/replication_transfer_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# See LICENSE.md for details.

class ReplicationTransferAdapter < ::AbstractAdapter
map_date :created_at, :created_at, Time::DATE_FORMATS[:dpn]
map_date :updated_at, :updated_at, Time::DATE_FORMATS[:dpn]
map_date :created_at, :created_at
map_date :updated_at, :updated_at

map_simple :replication_id, :replication_id
map_simple :fixity_nonce, :fixity_nonce
Expand Down
4 changes: 2 additions & 2 deletions app/adapters/restore_transfer_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class RestoreTransferAdapter < ::AbstractAdapter
map_date :created_at, :created_at, Time::DATE_FORMATS[:dpn]
map_date :updated_at, :updated_at, Time::DATE_FORMATS[:dpn]
map_date :created_at, :created_at
map_date :updated_at, :updated_at

map_simple :restore_id, :restore_id
map_bool :accepted, :accepted
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def convert_time_strings
[:updated_at, :created_at].each do |key|
if params.has_key?(key)
begin
timestamp = params[key].gsub(/\.[0-9]*Z\Z/, "Z")
params[key] = time_from_string(timestamp)
params[key] = Time.zone.parse(params[key])
rescue ArgumentError
params[key] = nil
end
Expand Down
11 changes: 0 additions & 11 deletions config/initializers/time_formats.rb

This file was deleted.

4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@
Kernel.srand config.seed
=end
end

def time_from_string(string_time)
Time.zone.parse(string_time)
end

0 comments on commit c8e206c

Please sign in to comment.