Skip to content

Commit 6a73fbd

Browse files
committed
Merge pull request #16 from tjdett/timezone-fix
Fixing handling for databases using UTC dates.
2 parents c9d6211 + 1d6f878 commit 6a73fbd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/oai/provider/model/activerecord_wrapper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ def sql_conditions(opts)
156156
def parse_to_local(time)
157157
time_obj = Time.parse(time.to_s)
158158
time_obj = yield(time_obj) if block_given?
159-
time_obj.localtime.strftime("%Y-%m-%d %H:%M:%S")
159+
# Convert to same as DB - :local => :getlocal, :utc => :getutc
160+
tzconv = "get#{model.default_timezone.to_s}".to_sym
161+
time_obj.send(tzconv).strftime("%Y-%m-%d %H:%M:%S")
160162
end
161163

162164
end

test/activerecord_provider/tc_ar_provider.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,19 @@ def setup
114114
end
115115

116116
end
117+
118+
class ActiveRecordProviderTimezoneTest < ActiveRecordProviderTest
119+
120+
def setup
121+
require 'active_record'
122+
ActiveRecord::Base.default_timezone = :utc
123+
super
124+
end
125+
126+
def teardown
127+
require 'active_record'
128+
ActiveRecord::Base.default_timezone = :local
129+
super
130+
end
131+
132+
end

0 commit comments

Comments
 (0)