test/test_timestamps.rb in swift-0.6.1 vs test/test_timestamps.rb in swift-0.7.0
- old
+ new
@@ -23,18 +23,35 @@
it 'should parse correctly when DST is off' do
time = DateTime.parse('2010-04-04 20:31:00+04:30')
assert_timestamp_like time, fetch_timestamp_at(time), 'DST off'
end
- def fetch_timestamp_at value
- sql = "select '%s'::timestamp with time zone as now" % value.strftime('%F %T%z')
+ describe 'Adapter timezone' do
+ %w(+05:30 -05:30).each do |offset|
+ it 'should parse timestamps and do conversion accordingly for offset ' + offset do
+ @db = Swift::DB::Postgres.new(@db.options.merge(timezone: offset))
+ server = DateTime.parse('2010-01-01 10:00:00')
+ local = DateTime.parse('2010-01-01 10:00:00 ' + offset)
+ assert_timestamp_like local, fetch_timestamp_at(server, ''), 'parses correctly'
+ end
+ end
+ end
+
+ def fetch_timestamp_at value, zone='%z'
+ sql = if zone.empty?
+ "select '%s'::timestamp as now"
+ else
+ "select '%s'::timestamp with time zone as now"
+ end
+
+ sql = sql % value.strftime('%F %T' + zone)
@db.execute(sql)
@db.results.first.fetch(:now)
end
def assert_timestamp_like expect, given, comment
match = Regexp.new expect.to_time.strftime('%F %T')
- assert_kind_of DateTime, given
+ assert_kind_of Time, given
assert_match match, given.strftime('%F %T'), comment
end
end
end
end