diff --git a/app/adapters/adapter.rb b/app/adapters/adapter.rb index bb615c31..899b9935 100644 --- a/app/adapters/adapter.rb +++ b/app/adapters/adapter.rb @@ -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 @@ -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 @@ -201,4 +201,4 @@ def to_bool(value) end -end \ No newline at end of file +end diff --git a/app/adapters/bag_adapter.rb b/app/adapters/bag_adapter.rb index 5296c5df..383e6156 100644 --- a/app/adapters/bag_adapter.rb +++ b/app/adapters/bag_adapter.rb @@ -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 diff --git a/app/adapters/fixity_check_adapter.rb b/app/adapters/fixity_check_adapter.rb index 5641587b..e47e7c66 100644 --- a/app/adapters/fixity_check_adapter.rb +++ b/app/adapters/fixity_check_adapter.rb @@ -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 diff --git a/app/adapters/ingest_adapter.rb b/app/adapters/ingest_adapter.rb index 676c405d..092e462d 100644 --- a/app/adapters/ingest_adapter.rb +++ b/app/adapters/ingest_adapter.rb @@ -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 diff --git a/app/adapters/member_adapter.rb b/app/adapters/member_adapter.rb index bb00336a..5d439530 100644 --- a/app/adapters/member_adapter.rb +++ b/app/adapters/member_adapter.rb @@ -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 diff --git a/app/adapters/message_digest_adapter.rb b/app/adapters/message_digest_adapter.rb index 97d6997c..305d704b 100644 --- a/app/adapters/message_digest_adapter.rb +++ b/app/adapters/message_digest_adapter.rb @@ -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 diff --git a/app/adapters/node_adapter.rb b/app/adapters/node_adapter.rb index c35ee7f4..4e24f5e0 100644 --- a/app/adapters/node_adapter.rb +++ b/app/adapters/node_adapter.rb @@ -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 diff --git a/app/adapters/replication_transfer_adapter.rb b/app/adapters/replication_transfer_adapter.rb index 3331e7c2..2872d4df 100644 --- a/app/adapters/replication_transfer_adapter.rb +++ b/app/adapters/replication_transfer_adapter.rb @@ -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 diff --git a/app/adapters/restore_transfer_adapter.rb b/app/adapters/restore_transfer_adapter.rb index 5e9e41e1..58bf4748 100644 --- a/app/adapters/restore_transfer_adapter.rb +++ b/app/adapters/restore_transfer_adapter.rb @@ -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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index abcd9ca1..1c1b7d01 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/config/initializers/time_formats.rb b/config/initializers/time_formats.rb deleted file mode 100644 index 22551e58..00000000 --- a/config/initializers/time_formats.rb +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) 2015 The Regents of the University of Michigan. -# All Rights Reserved. -# Licensed according to the terms of the Revised BSD License -# See LICENSE.md for details. - - -Time::DATE_FORMATS[:dpn] = "%Y-%m-%dT%H:%M:%SZ" - -def time_from_string(string_time) - Time.zone.parse(string_time.gsub(/\.[0-9]*Z\Z/, "Z")) -end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4847da25..974bba28 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -101,3 +101,7 @@ Kernel.srand config.seed =end end + +def time_from_string(string_time) + Time.zone.parse(string_time) +end