Skip to content

Commit ff09f2b

Browse files
authored
Account for time zones in DateTime serializations (#102)
* Use differing time zones in list test This proves the existence of a time zone-related bug where serializing with time zone information breaks equality checks. * Convert Date/DateTimes to UTC before serializing
1 parent 66d63ef commit ff09f2b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/kredis/type/datetime.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Kredis
44
module Type
55
class DateTime < ActiveModel::Type::DateTime
66
def serialize(value)
7-
super&.iso8601(9)
7+
super&.utc&.iso8601(9)
88
end
99

1010
def cast_value(value)

test/types/list_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ListTest < ActiveSupport::TestCase
4444
test "typed as datetime" do
4545
@list = Kredis.list "mylist", typed: :datetime
4646

47-
@list.append [ 1.day.from_now.midnight, 2.days.from_now.midnight ]
47+
@list.append [ 1.day.from_now.midnight.in_time_zone("Pacific Time (US & Canada)"), 2.days.from_now.midnight.in_time_zone("UTC") ]
4848
assert_equal [ 1.day.from_now.midnight, 2.days.from_now.midnight ], @list.elements
4949

5050
@list.remove(2.days.from_now.midnight)

0 commit comments

Comments
 (0)