Skip to content

Commit 36dafe0

Browse files
committed
Ensure datetimeoffset maintains offset.
1 parent 8d1da5b commit 36dafe0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

test/cases/column_test_sqlserver.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,26 @@ def assert_obj_set_and_save(attribute, value)
434434
obj.datetimeoffset_7.must_equal Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
435435
obj.reload
436436
obj.datetimeoffset_7.must_equal Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
437+
# Maintains the timezone
438+
time = ActiveSupport::TimeZone['America/Los_Angeles'].local 2010, 12, 31, 23, 59, 59, Rational(123456800, 1000)
439+
obj.datetimeoffset_7 = time
440+
obj.datetimeoffset_7.must_equal time
441+
obj.save!
442+
obj.datetimeoffset_7.must_equal time
443+
obj.reload.datetimeoffset_7.must_equal time
437444
# With other precisions.
438445
time = ActiveSupport::TimeZone['America/Los_Angeles'].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
439446
col = column('datetimeoffset_3')
440447
connection.lookup_cast_type_from_column(col).precision.must_equal 3
441448
obj.datetimeoffset_3 = time
442449
obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
443-
# TODO: FreeTDS date bug fixed: https://github.com/FreeTDS/freetds/issues/44
444-
obj.save! ; obj.reload
450+
obj.save!
445451
obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
446452
col = column('datetime2_1')
447453
connection.lookup_cast_type_from_column(col).precision.must_equal 1
448454
obj.datetime2_1 = time
449455
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
450-
obj.save! ; obj.reload
456+
obj.save!
451457
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
452458
end
453459

0 commit comments

Comments
 (0)